diff --git a/roles/neovim/tasks/Darwin.yaml b/roles/neovim/tasks/Darwin.yaml index 1f0de75..87c2d16 100644 --- a/roles/neovim/tasks/Darwin.yaml +++ b/roles/neovim/tasks/Darwin.yaml @@ -4,4 +4,4 @@ name: neovim state: latest -- include_tasks: unix.yaml +- include_tasks: Unix.yaml diff --git a/roles/neovim/tasks/Debian.yaml b/roles/neovim/tasks/Debian.yaml index 1109da2..777212c 100644 --- a/roles/neovim/tasks/Debian.yaml +++ b/roles/neovim/tasks/Debian.yaml @@ -5,4 +5,4 @@ name: neovim state: latest -- include_tasks: unix.yaml +- include_tasks: Unix.yaml diff --git a/roles/neovim/tasks/Unix-plugins.yaml b/roles/neovim/tasks/Unix-plugins.yaml new file mode 100644 index 0000000..1e690b6 --- /dev/null +++ b/roles/neovim/tasks/Unix-plugins.yaml @@ -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}}' diff --git a/roles/neovim/tasks/Unix.yaml b/roles/neovim/tasks/Unix.yaml new file mode 100644 index 0000000..f048928 --- /dev/null +++ b/roles/neovim/tasks/Unix.yaml @@ -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' diff --git a/roles/neovim/tasks/Windows-plugins.yaml b/roles/neovim/tasks/Windows-plugins.yaml new file mode 100644 index 0000000..bd77bbd --- /dev/null +++ b/roles/neovim/tasks/Windows-plugins.yaml @@ -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}}' diff --git a/roles/neovim/tasks/Windows.yaml b/roles/neovim/tasks/Windows.yaml index 7860714..e0f9a03 100644 --- a/roles/neovim/tasks/Windows.yaml +++ b/roles/neovim/tasks/Windows.yaml @@ -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' diff --git a/roles/neovim/tasks/unix.yaml b/roles/neovim/tasks/unix.yaml deleted file mode 100644 index 39ce262..0000000 --- a/roles/neovim/tasks/unix.yaml +++ /dev/null @@ -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