From afa70cf586ea0215919aa36a788679b24e2b7d8d Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Fri, 30 Aug 2024 09:13:26 +0100 Subject: [PATCH] idempotent fix --- tasks/gdu.yml | 3 ++- tasks/vim.yml | 14 ++++++++++---- tests/inventory | 1 + tests/test.yml | 9 +++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 tests/inventory create mode 100644 tests/test.yml diff --git a/tasks/gdu.yml b/tasks/gdu.yml index f0d4836..c002596 100644 --- a/tasks/gdu.yml +++ b/tasks/gdu.yml @@ -1,7 +1,8 @@ --- -- name: Get installed packages +- name: "Get installed packages" ansible.builtin.package_facts: manager: auto + when: ansible_facts.packages is not defined - name: "Ensure ncdu is removed" ansible.builtin.package: diff --git a/tasks/vim.yml b/tasks/vim.yml index 77fe8b9..49ff7f3 100644 --- a/tasks/vim.yml +++ b/tasks/vim.yml @@ -1,5 +1,5 @@ --- -- name: Get installed packages +- name: "Get installed packages" ansible.builtin.package_facts: manager: auto when: ansible_facts.packages is not defined @@ -16,7 +16,13 @@ state: directory owner: "{{ ansible_user_id }}" group: "{{ ansible_user_gid }}" - mode: '0755' + mode: "0755" + when: "'neovim' in ansible_facts.packages and disable_neovim_mouse_support" + +- name: "Check if init.vim exists" + ansible.builtin.stat: + path: "{{ lookup('env', 'HOME') }}/.config/nvim/init.vim" + register: init_vim_stat when: "'neovim' in ansible_facts.packages and disable_neovim_mouse_support" - name: "Ensure init.vim exists" @@ -25,8 +31,8 @@ state: touch owner: "{{ ansible_user_id }}" group: "{{ ansible_user_gid }}" - mode: '0644' - when: "'neovim' in ansible_facts.packages and disable_neovim_mouse_support" + mode: "0644" + when: "'neovim' in ansible_facts.packages and disable_neovim_mouse_support and not init_vim_stat.stat.exists" - name: "Disable mouse support in neovim" ansible.builtin.lineinfile: diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..2fbb50c --- /dev/null +++ b/tests/inventory @@ -0,0 +1 @@ +localhost diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..ed089a5 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,9 @@ + +--- +- name: "Test" + hosts: all + gather_facts: false + vars: + disable_neovim_mouse_support: true + roles: + - "../../ansible-role-linux_admin_packages"