Switch to Ansible for managing neovim plugins
This commit is contained in:
		
							parent
							
								
									7da67aaed0
								
							
						
					
					
						commit
						d95f1f7e32
					
				@ -4,4 +4,4 @@
 | 
			
		||||
    name: neovim
 | 
			
		||||
    state: latest
 | 
			
		||||
 | 
			
		||||
- include_tasks: unix.yaml
 | 
			
		||||
- include_tasks: Unix.yaml
 | 
			
		||||
 | 
			
		||||
@ -5,4 +5,4 @@
 | 
			
		||||
    name: neovim
 | 
			
		||||
    state: latest
 | 
			
		||||
 | 
			
		||||
- include_tasks: unix.yaml
 | 
			
		||||
- include_tasks: Unix.yaml
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										36
									
								
								roles/neovim/tasks/Unix-plugins.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								roles/neovim/tasks/Unix-plugins.yaml
									
									
									
									
									
										Normal 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}}'
 | 
			
		||||
							
								
								
									
										28
									
								
								roles/neovim/tasks/Unix.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								roles/neovim/tasks/Unix.yaml
									
									
									
									
									
										Normal 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'
 | 
			
		||||
							
								
								
									
										36
									
								
								roles/neovim/tasks/Windows-plugins.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								roles/neovim/tasks/Windows-plugins.yaml
									
									
									
									
									
										Normal 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}}'
 | 
			
		||||
@ -1,22 +1,28 @@
 | 
			
		||||
---
 | 
			
		||||
- set_fact:
 | 
			
		||||
    nvim_config_dir: '{{ansible_env.LOCALAPPDATA}}/nvim'
 | 
			
		||||
 | 
			
		||||
- name: install chocolatey packages
 | 
			
		||||
  win_chocolatey:
 | 
			
		||||
    name: neovim
 | 
			
		||||
    state: latest
 | 
			
		||||
 | 
			
		||||
- set_fact:
 | 
			
		||||
    vim_config_dir: '{{ansible_env.LOCALAPPDATA}}\nvim'
 | 
			
		||||
 | 
			
		||||
- name: clone config repo
 | 
			
		||||
  win_git:
 | 
			
		||||
    repo: git@code.infektor.net:config/vim.git
 | 
			
		||||
    dest: '{{nvim_config_dir}}'
 | 
			
		||||
    version: master
 | 
			
		||||
    dest: '{{vim_config_dir}}'
 | 
			
		||||
    branch: master
 | 
			
		||||
    # clone: false
 | 
			
		||||
    update: true
 | 
			
		||||
- win_owner:
 | 
			
		||||
    path: '{{nvim_config_dir}}'
 | 
			
		||||
    path: '{{vim_config_dir}}'
 | 
			
		||||
    user: Benie
 | 
			
		||||
    recurse: true
 | 
			
		||||
 | 
			
		||||
- assert:
 | 
			
		||||
    that: False
 | 
			
		||||
 | 
			
		||||
# - TODO: neovim set repo email
 | 
			
		||||
#   win_git_config:
 | 
			
		||||
# - TODO: neovim install pip packages
 | 
			
		||||
@ -30,3 +36,27 @@
 | 
			
		||||
    dest: '{{ansible_env.ProgramData}}/Microsoft/Windows/Start Menu/Programs/nvim-qt.lnk'
 | 
			
		||||
    icon: '{{ansible_env.ChocolateyToolsLocation}}/neovim/nvim-win64/bin/nvim-qt.exe,0'
 | 
			
		||||
    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'
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user