Improve bat role
This commit is contained in:
parent
189371d7f2
commit
76b6d63064
@ -7,6 +7,7 @@
|
||||
- role: system-info
|
||||
|
||||
- role: ag
|
||||
- role: bat
|
||||
- role: fzf
|
||||
- role: git
|
||||
- role: tree
|
||||
|
@ -1,13 +1,13 @@
|
||||
---
|
||||
- name: install apt package
|
||||
become: true
|
||||
apt:
|
||||
name: bat
|
||||
state: latest
|
||||
- set_fact:
|
||||
use_github: '{{
|
||||
ansible_distribution == "Ubuntu" and
|
||||
ansible_distribution_version == "18.04"
|
||||
}}'
|
||||
- debug: msg={{use_github}}
|
||||
|
||||
- name: update bat alternative
|
||||
become: true
|
||||
alternatives:
|
||||
name: bat
|
||||
path: /usr/bin/batcat
|
||||
link: /usr/local/bin/bat
|
||||
- when: use_github
|
||||
include_tasks: deb.yaml
|
||||
|
||||
- when: not use_github
|
||||
include_tasks: apt.yaml
|
||||
|
5
roles/bat/tasks/Windows.yaml
Normal file
5
roles/bat/tasks/Windows.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: install chocolatey package
|
||||
win_chocolatey:
|
||||
name: Bat
|
||||
state: latest
|
13
roles/bat/tasks/apt.yaml
Normal file
13
roles/bat/tasks/apt.yaml
Normal file
@ -0,0 +1,13 @@
|
||||
---
|
||||
- name: install apt package
|
||||
become: true
|
||||
apt:
|
||||
name: bat
|
||||
state: latest
|
||||
|
||||
- name: update bat alternative
|
||||
become: true
|
||||
alternatives:
|
||||
name: bat
|
||||
path: /usr/bin/batcat
|
||||
link: /usr/local/bin/bat
|
65
roles/bat/tasks/deb.yaml
Normal file
65
roles/bat/tasks/deb.yaml
Normal file
@ -0,0 +1,65 @@
|
||||
---
|
||||
- name: get latest github release
|
||||
uri:
|
||||
url: https://api.github.com/repos/sharkdp/bat/releases/latest
|
||||
register: latest
|
||||
|
||||
- set_fact:
|
||||
latest_version: '{{latest.json.tag_name[1:]}}'
|
||||
bat_exe: '/usr/bin/bat'
|
||||
|
||||
- name: check if already installed
|
||||
stat:
|
||||
path: '{{bat_exe}}'
|
||||
register: bat_stat
|
||||
|
||||
- name: get installed version
|
||||
when: bat_stat.stat.exists == True
|
||||
command: '{{bat_exe}} --version'
|
||||
register: bat_version
|
||||
changed_when: false
|
||||
|
||||
- when: bat_stat.stat.exists == True
|
||||
set_fact:
|
||||
installed_version:
|
||||
'{{bat_version.stdout.strip() | regex_replace("^.*(\d+\.\d+\.\d+).*$", "\1")}}'
|
||||
|
||||
- when: ansible_machine == "x86_64"
|
||||
set_fact:
|
||||
arch: amd64
|
||||
|
||||
- assert:
|
||||
that: arch is defined
|
||||
fail_msg: 'Architecture not currently supported: {{ansible_machine}}'
|
||||
|
||||
- set_fact:
|
||||
assets: '{{latest.json.assets}}'
|
||||
asset_query: '[?contains(name, `bat-musl_`)] | [?contains(name, `amd64.deb`)] | [0]'
|
||||
pkg_dir: '{{ansible_env.HOME}}/.local/pkg/bat'
|
||||
- set_fact:
|
||||
asset: '{{assets | to_json | from_json | json_query(asset_query)}}'
|
||||
bat_deb: '{{pkg_dir}}/bat.deb'
|
||||
|
||||
- name: create directory for deb file download
|
||||
file:
|
||||
state: directory
|
||||
path: '{{pkg_dir}}'
|
||||
|
||||
- name: download .deb file
|
||||
when: installed_version is not defined or installed_version != latest_version
|
||||
get_url:
|
||||
url: '{{asset.browser_download_url}}'
|
||||
dest: '{{bat_deb}}'
|
||||
|
||||
- name: install .deb file
|
||||
when: installed_version is not defined or installed_version != latest_version
|
||||
become: true
|
||||
apt:
|
||||
deb: '{{bat_deb}}'
|
||||
|
||||
- name: remove .deb file
|
||||
when: installed_version is not defined or installed_version != latest_version
|
||||
file:
|
||||
state: absent
|
||||
path: '{{bat_deb}}'
|
||||
changed_when: false
|
Loading…
x
Reference in New Issue
Block a user