Skip to content

Commit

Permalink
Removes explicit group and mode handling from tasks and tests
Browse files Browse the repository at this point in the history
- Since the last release, we've been handling all file operations *as* a certain
  user, so we can rely on that to ensure the group and mode are set in line with
  the system's configuration.
- We're still testing for group since (in the context of the tests) a group that
  is NOT identical to vim_owner is a sign that something's gone wrong with some
  task's become and become_user settings.
- Re: pr25-fix-intermittent-non-zero-return-code
  • Loading branch information
ctorgalson committed Jun 17, 2022
1 parent 1e16047 commit 1420f66
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 39 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ The following variables are used in the role. See also Example Playbook
| `vim_installed_packages` | `["vim"]` | A list of packages to install (passed to Ansible's Package module). |
| `vim_removed_packages` | `[]` | A list of packages to remove (e.g. on Ubuntu, it might be preferable to remove `vim-tiny`). |
| `vim_owner` | `""` | The system user to install Vim and/or associated plugins for. |
| `vim_group` | `""` | The group of the user specificed in `vim_owner`. |
| `vim_file_mode` | `'644'` | The permissions string to set on files copied or created by the role. |
| `vim_dir_mode` | `'755'` | The permissions string to set on directories copied or created by the role. |
| `vim_pack_subdirectory` | `ansible-managed` | The name of the directory to place plugins installed by this role into the default creates e.g. `~/.vim/pack/ansible-managed/start` and `~/.vim/pack/ansible-managed/opt`. |
| `vim_installed_plugins` | `[]` | The list of plugins to install to `~/.vim/pack/ansible-managed/start`--see `:help packages` for details on what this means. Should contain a `repo` property, a `type` property set to either 'start' or 'opt', and (optionally) a `version` property as used by Ansible's Git module. |
| `vim_removed_plugins` | `[]` | A list of plugins to remove from `~/.vim/pack/ansible-managed/{opt,start}`. Each should contain a directory property set to the directory name of the plugin, and a `type` property set to either 'start' or 'opt'. |
Expand All @@ -56,7 +53,6 @@ The following variables are used in the role. See also Example Playbook
vim_removed_packages:
- "vim-tiny"
vim_owner: "molecule"
vim_group: "molecule"
vim_installed_plugins:
- repo: "https://github.com/altercation/vim-colors-solarized.git"
type: "start"
Expand Down
3 changes: 0 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ vim_installed_packages:
- "vim"
vim_removed_packages: []
vim_owner: ""
vim_group: ""
# vim_file_mode: "644"
# vim_dir_mode: "755"
vim_pack_subdirectory: "ansible-managed"
vim_installed_plugins: []
# - repo: "https://github.com/scrooloose/nerdtree.git"
Expand Down
1 change: 0 additions & 1 deletion molecule/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
vim_removed_packages:
- "vim-tiny"
vim_owner: "molecule"
vim_group: "molecule"
vim_dotfiles:
- "{{ playbook_dir }}/files/dotfiles/.vimrc"
tasks:
Expand Down
8 changes: 3 additions & 5 deletions molecule/tests/test-config-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
(not rg__config_file.stat.exists and config_file.state == 'absent')
fail_msg: "The config file '{{ config_file_name }}' is not {{ config_file.state }}."

- name: "Verify owner, group, and mode of '{{ config_file_name }}'."
- name: "Verify owner and group of '{{ config_file_name }}'."
assert:
that:
- "rg__config_file.stat.pw_name == fact__vim_owner"
- "rg__config_file.stat.gr_name == fact__vim_owner"
- "rg__config_file.stat.mode == config_file.mode"
fail_msg: >
The owner, group, or mode of the '{{ config_file }}' file was
The owner or group of the '{{ config_file }}' file was
incorrect. Found {{ rg__config_file.stat.pw_name }} (owner),
{{ rg__config_file.stat.gr_name }} (group), and
{{ rg__config_file.stat.mode }} (mode).
{{ rg__config_file.stat.gr_name }} (group).
6 changes: 2 additions & 4 deletions molecule/tests/test-directories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
that:
- "rg__dir_path.stat.pw_name == fact__vim_owner"
- "rg__dir_path.stat.gr_name == fact__vim_owner"
- "rg__dir_path.stat.mode == fact__plugin_dir_mode"
fail_msg: >
The owner, group, or mode of the '{{ dir_name }}' {{ dir.type }} was
The owner or group of the '{{ dir_name }}' {{ dir.type }} was
incorrect. Found owner '{{ rg__dir_path.stat.pw_name }}' ({{ fact__vim_owner }}),
group '{{ rg__dir_path.stat.gr_name }}' ({{ fact__vim_owner }}), and
mode '{{ rg__dir_path.stat.mode }}' ({{ fact__plugin_dir_mode }}).
group '{{ rg__dir_path.stat.gr_name }}' ({{ fact__vim_owner }}).
when: "rg__dir_path.stat.exists and dir.state == 'present'"
8 changes: 3 additions & 5 deletions molecule/tests/test-helptags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
that: "rg__plugin_tags.stat.exists"
fail_msg: "No helptags file was found for the '{{ plugin_name }}' plugin."

- name: "Verify owner, group, and mode of '{{ plugin_name }}' plugin helptags file."
- name: "Verify owner and group of '{{ plugin_name }}' plugin helptags file."
assert:
that:
- "rg__plugin_tags.stat.pw_name == fact__vim_owner"
- "rg__plugin_tags.stat.gr_name == fact__vim_owner"
- "rg__plugin_tags.stat.mode == fact__helptags_mode"
fail_msg: >
The owner, group, or mode of the '{{ plugin_name }}' plugin helptags
The owner or group of the '{{ plugin_name }}' plugin helptags
file was incorrect. Found owner '{{ rg__plugin_tags.stat.pw_name }}' ({{ fact__vim_owner }}),
group '{{ rg__plugin_tags.stat.gr_name }}' ({{ fact__vim_owner }}), and
mode '{{ rg__plugin_tags.stat.mode }}' ({{ fact__helptags_mode }}).
and group '{{ rg__plugin_tags.stat.gr_name }}' ({{ fact__vim_owner }}).
9 changes: 0 additions & 9 deletions molecule/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
ansible.builtin.set_fact:
fact__vim_home_directory: "/home/{{ fact__vim_owner }}"

- name: "Test | prepare plugin dir mode for tests."
ansible.builtin.set_fact:
fact__plugin_dir_mode: "{{ (ansible_distribution_version == '22.04')|ternary('0755', '0775') }}"
fact__helptags_mode: "{{ (ansible_distribution_version == '22.04')|ternary('0644', '0664') }}"

- name: "Test | prepare package, file, directory, and plugin vars for tests."
ansible.builtin.set_fact:
fact__vim_packages:
Expand All @@ -28,20 +23,16 @@
fact__vim_config_files:
- path: "{{ fact__vim_home_directory }}/.vimrc"
state: present
mode: "0644"
fact__vim_directories:
- path: "{{ fact__vim_home_directory }}/.vim/pack/ansible-managed"
state: present
type: "directory"
mode: "0755"
- path: "{{ fact__vim_home_directory }}/.vim/pack/ansible-managed/start"
state: present
type: "directory"
mode: "0755"
- path: "{{ fact__vim_home_directory }}/.vim/pack/ansible-managed/opt"
state: present
type: "directory"
mode: "0755"
fact__vim_plugins:
# Installed plugins.
- path: "{{ fact__vim_home_directory }}/.vim/pack/ansible-managed/opt/vdebug"
Expand Down
3 changes: 0 additions & 3 deletions tasks/copy-dotfiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
ansible.builtin.copy:
src: "{{ dotfile }}"
dest: "{{ vim_user_home_directory }}/{{ dotfile | basename }}"
owner: "{{ vim_owner }}"
group: "{{ vim_group }}"
mode: "{{ vim_file_mode | default('644') }}"
become: true
become_user: "{{ vim_owner }}"
loop: "{{ vim_dotfiles }}"
Expand Down
7 changes: 2 additions & 5 deletions tasks/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
changed_when: false

- name: Make sure it even makes sense to continue.
ansible.builtin.assert:
that: "{{ vim_version_string.stdout is version('8.0', '>=') }}"
ansible.builtin.fail:
msg: "Vim does not support native package management in versions lower than 8.0."
when: "{{ vim_version_string.stdout is version('8.0', '<') }}"

- name: Determine home directory.
ansible.builtin.set_fact:
Expand All @@ -38,9 +38,6 @@
ansible.builtin.file:
path: "{{ vim_plugin_parent_directory }}/{{ vim_directory }}"
state: directory
owner: "{{ vim_owner }}"
group: "{{ vim_group }}"
mode: "{{ vim_dir_mode | default('755') }}"
become: true
become_user: "{{ vim_owner }}"
loop:
Expand Down

0 comments on commit 1420f66

Please sign in to comment.