diff --git a/roles/neovim/tasks/Debian.yaml b/roles/neovim/tasks/Debian.yaml index 5049d48..0aece75 100644 --- a/roles/neovim/tasks/Debian.yaml +++ b/roles/neovim/tasks/Debian.yaml @@ -1,26 +1,108 @@ --- -- name: slurp /etc/os-release - slurp: - src: /etc/os-release - register: os_release_slurp -- set_fact: - os_release: "{{ os_release_slurp.content | - b64decode | trim() | replace('=', ': ') | from_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: add neovim stable ppa - when: "'ID_LIKE' in os_release and os_release.ID_LIKE == 'ubuntu debian'" +- name: remove apt package become: true - apt_repository: - repo: ppa:neovim-ppa/stable - codename: '{{os_release.UBUNTU_CODENAME}}' - update_cache: true + apt: + name: neovim + state: absent -- name: install apt package +- name: install python provider apt package become: true apt: name: - - neovim - python3-neovim + - stow 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 + 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