local/roles/neovim/tasks/Debian.yaml
Kenneth Benzie (Benie) e711b9f3b2 Add optional GitHub API authentication headers
If the `GITHUB_TOKEN` is defined in the Ansible controller's
environment it is used to set the GitHub REST API authentication header.
This is they passed to all `uri` modules tasks which interact with the
GitHub REST API. If the `GITHUB_TOKEN` is not set, the authentication
header is not used.

Fixes #19
2024-04-06 16:35:01 +01:00

115 lines
2.6 KiB
YAML

---
# Don't neovim packages because they are all behind, even Debian unstable.
# Instead use the latest pre-build Linux package from GitHub, then stow them
# into /usr/local.
- name: remove apt package
become: true
apt:
name: neovim
state: absent
- name: install gnu stow for managing tar.gz package
become: true
apt:
name:
- stow
state: latest
- name: install python provider pip package
become: true
pip:
name: pynvim
state: latest
- name: stat installed executable
stat:
path: /usr/local/bin/nvim
register: nvim
- name: get installed version
when: nvim.stat.exists
command: nvim --version
register: nvim_version
changed_when: false
- when: nvim.stat.exists
set_fact:
installed_version: '{{nvim_version.stdout_lines[0][5:]}}'
- name: get latest version
uri:
url: https://api.github.com/repos/neovim/neovim/releases/latest
headers: '{{github_auth_headers}}'
register: latest
- set_fact:
install_required:
'{{installed_version is not defined or
installed_version != latest.json.tag_name}}'
asset_query: '[?contains(name, `nvim-linux64.tar.gz`)]'
package_dir: '/usr/local/lib/nvim'
- set_fact:
uninstall_required: '{{nvim.stat.exists and install_required}}'
asset: '{{latest.json.assets | json_query(asset_query)}}'
package_path: '{{package_dir}}/{{latest.json.name}}'
- name: uninstall old package from /usr/local
when: uninstall_required
become: true
command:
cmd: 'stow --delete --target /usr/local .'
chdir: '{{package_dir}}/nvim-linux64'
- name: remove old package
become: true
when: uninstall_required
file:
path: '{{package_dir}}/nvim-linux64'
state: absent
- name: create package directory
become: true
file:
path: '{{package_dir}}'
state: directory
- name: download package archive
when: install_required
become: true
get_url:
url: '{{asset[0].browser_download_url}}'
dest: '{{package_path}}'
- name: extract package archive
when: install_required
become: true
unarchive:
src: '{{package_path}}'
dest: '{{package_dir}}'
- name: remove downloaded archive
when: install_required
become: true
file:
path: '{{package_path}}'
state: absent
- name: move man to share/man
when: install_required
become: true
command:
argv:
- mv
- '{{package_dir}}/nvim-linux64/man'
- '{{package_dir}}/nvim-linux64/share'
- name: install package to /usr/local
when: install_required
become: true
command:
cmd: 'stow --target /usr/local .'
chdir: '{{package_dir}}/nvim-linux64'
- include_tasks: Unix.yaml