Switch to Ansible for managing neovim plugins

This commit is contained in:
Kenneth Benzie 2022-11-08 15:49:54 +00:00
parent 7da67aaed0
commit d95f1f7e32
7 changed files with 137 additions and 21 deletions

View File

@ -4,4 +4,4 @@
name: neovim name: neovim
state: latest state: latest
- include_tasks: unix.yaml - include_tasks: Unix.yaml

View File

@ -5,4 +5,4 @@
name: neovim name: neovim
state: latest state: latest
- include_tasks: unix.yaml - include_tasks: Unix.yaml

View File

@ -0,0 +1,36 @@
---
- name: clone plugin repos
git:
repo: 'https://github.com/{{item.repo}}.git'
dest: '{{plugin_dir}}/{{item.mode | default("start")}}/{{item.repo | regex_replace("^.*\/(.*)$", "\1")}}'
version: '{{item.branch | default("HEAD")}}'
with_items: '{{plugins}}'
- name: get list of managed plugin paths
set_fact:
managed_plugins: >-
{{
managed_plugins | default([]) + [
plugin_dir + "/" +
item.mode | default("start") + "/" +
item.repo | regex_replace("^.*\/(.*)$", "\1")
]
}}
with_items: '{{plugins}}'
- name: find all installed plugin directories
find:
paths:
- '{{plugin_dir}}/start'
- '{{plugin_dir}}/opt'
file_type: directory
register: found_plugins
- name: remove found plugins which are not in the managed list
file:
path: '{{item.path}}'
state: absent
with_items: '{{found_plugins.files}}'
when: item.path not in managed_plugins
loop_control:
label: '{{item.path}}'

View File

@ -0,0 +1,28 @@
---
- set_fact:
vim_config_dir: '{{ansible_env.HOME}}/.config/nvim'
- name: clone config repo
git:
repo: git@code.infektor.net:config/vim.git
dest: '{{vim_config_dir}}'
version: master
# TODO: - name: set repo email
- name: install pip packages
pip:
name: '{{neovim_pip_packages}}'
state: latest
extra_args: --user
- name: check for config repo tasks.yaml
stat:
path: '{{vim_config_dir}}/tasks.yaml'
register: config_repo_tasks
- when: config_repo_tasks.stat.exists
include_tasks: '{{vim_config_dir}}/tasks.yaml'
- when: plugin_dir is defined and plugins is defined
include_tasks: 'Unix-plugins.yaml'

View File

@ -0,0 +1,36 @@
---
- name: clone plugin repos
win_git:
repo: 'https://github.com/{{item.repo}}.git'
dest: '{{plugin_dir}}/{{item.mode | default("start")}}/{{item.repo | regex_replace("^.*\/(.*)$", "\1")}}'
branch: '{{item.branch | default("HEAD")}}'
with_items: '{{plugins}}'
- name: get list of managed plugin paths
set_fact:
managed_plugins: >-
{{
managed_plugins | default([]) + [
plugin_dir + "/" +
item.mode | default("start") + "/" +
item.repo | regex_replace("^.*\/(.*)$", "\1")
]
}}
with_items: '{{plugins}}'
- name: find all start plugin directories
win_find:
paths:
- '{{plugin_dir}}/start'
- '{{plugin_dir}}/opt'
file_type: directory
register: found_plugins
- name: remove found plugins which are not in the managed list
win_file:
path: '{{item.path}}'
state: absent
with_items: '{{found_plugins.files}}'
when: item.path not in managed_plugins
loop_control:
label: '{{item.path}}'

View File

@ -1,22 +1,28 @@
--- ---
- set_fact:
nvim_config_dir: '{{ansible_env.LOCALAPPDATA}}/nvim'
- name: install chocolatey packages - name: install chocolatey packages
win_chocolatey: win_chocolatey:
name: neovim name: neovim
state: latest state: latest
- set_fact:
vim_config_dir: '{{ansible_env.LOCALAPPDATA}}\nvim'
- name: clone config repo - name: clone config repo
win_git: win_git:
repo: git@code.infektor.net:config/vim.git repo: git@code.infektor.net:config/vim.git
dest: '{{nvim_config_dir}}' dest: '{{vim_config_dir}}'
version: master branch: master
# clone: false
update: true
- win_owner: - win_owner:
path: '{{nvim_config_dir}}' path: '{{vim_config_dir}}'
user: Benie user: Benie
recurse: true recurse: true
- assert:
that: False
# - TODO: neovim set repo email # - TODO: neovim set repo email
# win_git_config: # win_git_config:
# - TODO: neovim install pip packages # - TODO: neovim install pip packages
@ -30,3 +36,27 @@
dest: '{{ansible_env.ProgramData}}/Microsoft/Windows/Start Menu/Programs/nvim-qt.lnk' dest: '{{ansible_env.ProgramData}}/Microsoft/Windows/Start Menu/Programs/nvim-qt.lnk'
icon: '{{ansible_env.ChocolateyToolsLocation}}/neovim/nvim-win64/bin/nvim-qt.exe,0' icon: '{{ansible_env.ChocolateyToolsLocation}}/neovim/nvim-win64/bin/nvim-qt.exe,0'
directory: '{{ansible_env.USERPROFILE}}' directory: '{{ansible_env.USERPROFILE}}'
- name: check for config repo tasks.yaml
win_stat:
path: '{{vim_config_dir}}/tasks.yaml'
register: config_repo_tasks
# TODO: this doesn't work for non localhost setups
# probably need to copy the tasks.yaml and plugins.yaml to the controller in a
# temporary directory then include them
- when: config_repo_tasks.stat.exists
fetch:
src: '{{vim_config_dir}}/tasks.yaml'
dest: vim_config_tasks.yaml
flat: true
- when: config_repo_tasks.stat.exists
include_tasks: vim_config_tasks.yaml
- when: ansible_os_family != "Windows" and
plugin_dir is defined and plugins is defined
include_tasks: 'Unix-plugins.yaml'
- when: ansible_os_family == "Windows" and
plugin_dir is defined and plugins is defined
include_tasks: 'Windows-plugins.yaml'

View File

@ -1,14 +0,0 @@
---
- name: clone config repo
git:
repo: git@code.infektor.net:config/vim.git
dest: ~/.config/nvim
version: master
# TODO: - name: set repo email
- name: install pip packages
pip:
name: '{{neovim_pip_packages}}'
state: latest
extra_args: --user