Last active
April 21, 2021 00:22
-
-
Save spicyjack/2032018f708a89d8811b031a1d9d2e05 to your computer and use it in GitHub Desktop.
Set up VIM via an Ansible playbook task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| # this task list should be called via 'import_tasks' | |
| - name: "Set a variable with a timestamp" | |
| set_fact: | |
| timestamp: "{{lookup('pipe', 'date \"+%Y-%m-%d.%H%M\"')}}" | |
| ### SET UP VIM | |
| - name: "Copying '~/.vimrc' to '~/.vimrc.{{ timestamp }}'" | |
| copy: | |
| src: "~/.vimrc" | |
| dest: "~/.vimrc.{{ timestamp }}" | |
| # octal mode apparently always needs the leading '0', which is confusing | |
| owner: "{{ user_name }}" | |
| group: "{{ user_group }}" | |
| mode: 0644 | |
| remote_src: yes | |
| - name: "Remove '~/.vimrc' file" | |
| file: | |
| path: "~/.vimrc" | |
| state: absent | |
| ### SET UP VIM on the remote host | |
| - name: "Set up VIM directories for '{{ user_name }}'" | |
| file: | |
| # from "vars/vim_plugins.yaml" | |
| path: "{{ vim_subdirs_list }}" | |
| owner: "{{ user_name }}" | |
| group: "{{ user_group }}" | |
| state: "directory" | |
| mode: 0700 | |
| ### INSTALL Pathogen | |
| # - name: "Install Pathogen via 'get_url'" | |
| # get_url: | |
| # url: "https://tpo.pe/pathogen.vim" | |
| # dest: "~/.vim/autoload/pathogen.vim" | |
| # owner: "{{ user_name }}" | |
| # group: "{{ user_group }}" | |
| # mode: 0644 | |
| # - name: "Copy Pathogen '~/.vimrc'" | |
| # copy: | |
| # src: ../files/vimrc.pathogen.vim | |
| # dest: "{{ user_home_dir }}/.vimrc" | |
| # owner: "{{ user_name }}" | |
| # group: "{{ user_group }}" | |
| # mode: 0644 | |
| # backup: yes | |
| # - name: "Clone 'Deoplete' and 'snippet' repos" | |
| # git: | |
| # repo: "{{ item }}" | |
| # dest: "{{ vim_bundle_path }}" | |
| # force: yes | |
| # update: yes | |
| # loop: | |
| # - "https://github.com/Shougo/deoplete.nvim.git" | |
| # - "https://github.com/Shougo/neosnippet.vim.git" | |
| # - "https://github.com/roxma/nvim-yarp.git" | |
| # - "https://github.com/roxma/vim-hug-neovim-rpc.git" | |
| # - "https://github.com/honza/vim-snippets.git" | |
| # become: yes | |
| # become_user: "{{ user_name }}" | |
| # - name: "Install 'pynvim' Python module for VIM" | |
| # shell: > | |
| # pip3 install --user pynvim | |
| # become: yes | |
| # become_user: "{{ user_name }}" | |
| ### INSTALL CoC | |
| - name: "Install Conqueror of Completion via 'get_url'" | |
| get_url: | |
| url: "https://github.com/neoclide/coc.nvim/archive/release.tar.gz" | |
| dest: "{{ vim_plugs_path }}" | |
| owner: "{{ user_name }}" | |
| group: "{{ user_group }}" | |
| mode: 0644 | |
| - name: "Unarchive 'Conqueror of Completion'" | |
| unarchive: | |
| src: "{{ vim_plugs_path }}/coc.nvim-release.tar.gz" | |
| dest: "{{ vim_plugs_path }}" | |
| owner: "{{ user_name }}" | |
| group: "{{ user_group }}" | |
| list_files: True | |
| remote_src: yes | |
| - name: "Remove 'Conqueror of Completion' 'coc.nvim-release.tar.gz'" | |
| file: | |
| path: "{{ vim_plugs_path}}/coc.nvim-release.tar.gz" | |
| state: absent | |
| # difference between 'start' and 'opt' plugin directories | |
| # - https://vi.stackexchange.com/questions/20810/ | |
| # using regular expression functions as filters | |
| # - https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#searching-strings-with-regular-expressions | |
| # - https://stackoverflow.com/questions/55046531/ansible-regex-search-with-variable | |
| - name: "Clone plugins into '{{ vim_plugs_path }}'" | |
| git: | |
| # from "vars/vim_plugins.yaml" | |
| repo: "{{ vim_plugs_list }}" | |
| dest: "{{ vim_plugs_path }}/{{ item | regex_replace('.*/(.*)$', '\\1')}}" | |
| force: yes | |
| update: yes | |
| loop: | |
| become: yes | |
| become_user: "{{ user_name }}" | |
| - name: "Clone VIM syntax plugins into '{{ vim_syns_path }}'" | |
| git: | |
| # from "vars/vim_plugins.yaml" | |
| repo: "{{ vim_syns_list }}" | |
| dest: "{{ vim_syns_path }}/{{ item | regex_replace('.*/(.*)$', '\\1')}}" | |
| force: yes | |
| update: yes | |
| loop: | |
| become: yes | |
| become_user: "{{ user_name }}" | |
| ### WRITE RECEIPT ### | |
| - name: "Set 'playbook_name' and call 'ansible-write_playbook_receipt'" | |
| set_fact: playbook_name="user-setup_vim_and_friends-{{user_name}}" | |
| # write a receipt for this playbook | |
| - import_tasks: ../tasks/ansible-write_playbook_receipt.yaml | |
| ... | |
| # vim: filetype=yaml shiftwidth=2 tabstop=2: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment