mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
8635cd84d4
* feature: module dpkg_divert + tests * try to skip non-deb linux distrib * use collection namespace in EXAMPLES * skip unsupported OS/distrib in tasks instead * tests: remove unskipped distribs * apply changes suggested by Andersson007 * Remove ANSIBLE_METADATA (no more needed). * Normalize docstrings (capitalize descriptions, fix styling, use yes/no booleans). * fix descriptions * update DOCUMENTATION * Drop field 'version_added' (no more needed). * Add a note about check_mode support. * use list comprehension * support diff mode * Move 'before'/'after' dicts into 'diff' dictionary. * Set 'diversion' as the actual state (or the state that would be reached, when in check mode). * Always return 'diversion' on handled exits (exit_json & fail_json). * enable 'diff' mode in tests, add missing 'become'
287 lines
7.4 KiB
YAML
287 lines
7.4 KiB
YAML
---
|
|
################################################################################
|
|
# TEST 01: state=present
|
|
|
|
- name: "create foobarrc for tests"
|
|
copy:
|
|
dest: "{{ foobarrc }}"
|
|
content: "{{ foobarrc_oldtext }}"
|
|
|
|
|
|
- name: "divert foobarrc (check mode, must report a change)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
state: present
|
|
register: diversion_0
|
|
check_mode: true
|
|
|
|
- name: "divert foobarrc (must report a change)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
state: present
|
|
register: diversion_1
|
|
|
|
|
|
- name: "divert foobarrc (must NOT report a change, idempotency)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
state: present
|
|
register: diversion_2
|
|
|
|
- name: "divert foobarrc (check mode, must NOT report a change, idempotency)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
state: present
|
|
register: diversion_3
|
|
check_mode: true
|
|
|
|
|
|
# Ensure that 'rename' has no effect when state is not changed
|
|
|
|
- name: "divert foobarrc (rename, must NOT report a change, idempotency)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
state: present
|
|
rename: yes
|
|
register: diversion_4
|
|
|
|
- name: "divert foobarrc (check mode, rename, must NOT report a change, idempotency)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
state: present
|
|
rename: yes
|
|
register: diversion_5
|
|
check_mode: true
|
|
|
|
|
|
# Check results
|
|
|
|
- name: "stat foobarrc (must still be there)"
|
|
stat:
|
|
path: "{{ foobarrc }}"
|
|
register: diversion_6
|
|
|
|
- name: "stat foobarrc.distrib (must not exist)"
|
|
stat:
|
|
path: "{{ foobarrc_distrib }}"
|
|
register: diversion_7
|
|
|
|
- name: "assert that results of test 01 are as expected"
|
|
assert:
|
|
that:
|
|
- diversion_0 is changed
|
|
- diversion_1 is changed
|
|
- diversion_2 is not changed
|
|
- diversion_3 is not changed
|
|
- diversion_4 is not changed
|
|
- diversion_5 is not changed
|
|
- diversion_6.stat.exists
|
|
- diversion_6.stat.checksum == foobarrc_oldsha1
|
|
- not diversion_7.stat.exists
|
|
- diversion_0.diversion == diversion_1.diversion
|
|
- diversion_2.diversion == diversion_3.diversion
|
|
- diversion_4.diversion == diversion_5.diversion
|
|
- diversion_0.commands == diversion_1.commands
|
|
- diversion_2.commands == diversion_3.commands
|
|
- diversion_4.commands == diversion_5.commands
|
|
quiet: yes
|
|
|
|
|
|
################################################################################
|
|
# TEST 02: state=absent
|
|
|
|
- name: "remove diversion for foobarrc (check mode, must report a change)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
state: absent
|
|
register: diversion_0
|
|
check_mode: true
|
|
|
|
- name: "remove diversion for foobarrc (must report a change)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
state: absent
|
|
register: diversion_1
|
|
|
|
|
|
- name: "remove diversion for foobarrc (must NOT report a change, idempotency)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
state: absent
|
|
register: diversion_2
|
|
|
|
- name: "remove diversion for foobarrc (check mode, must NOT report a change, idempotency)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
state: absent
|
|
register: diversion_3
|
|
check_mode: true
|
|
|
|
|
|
# Check results
|
|
|
|
- name: "stat foobarrc (must still be there)"
|
|
stat:
|
|
path: "{{ foobarrc }}"
|
|
register: diversion_4
|
|
|
|
- name: "stat foobarrc.distrib (must not exist)"
|
|
stat:
|
|
path: "{{ foobarrc_distrib }}"
|
|
register: diversion_5
|
|
|
|
- name: "assert that results of test 02 are as expected"
|
|
assert:
|
|
that:
|
|
- diversion_0 is changed
|
|
- diversion_1 is changed
|
|
- diversion_2 is not changed
|
|
- diversion_3 is not changed
|
|
- diversion_4.stat.exists
|
|
- diversion_4.stat.checksum == foobarrc_oldsha1
|
|
- not diversion_5.stat.exists
|
|
- diversion_0.diversion == diversion_1.diversion
|
|
- diversion_2.diversion == diversion_3.diversion
|
|
- diversion_0.commands == diversion_1.commands
|
|
- diversion_2.commands == diversion_3.commands
|
|
quiet: yes
|
|
|
|
|
|
################################################################################
|
|
# TEST 03: holder=ansible
|
|
|
|
- name: "create foobarrc diversion with defaults"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
|
|
|
|
- name: "update foobarrc diversion holder (check mode, must report a change)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
holder: "ansible"
|
|
register: diversion_0
|
|
check_mode: yes
|
|
|
|
- name: "update foobarrc diversion holder (must report a change)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
holder: "ansible"
|
|
register: diversion_1
|
|
|
|
|
|
- name: "update foobarrc diversion holder (must NOT report a change, idempotency)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
holder: "ansible"
|
|
register: diversion_2
|
|
|
|
- name: "update foobarrc diversion holder (check mode, must NOT report a change, idempotency)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
holder: "ansible"
|
|
register: diversion_3
|
|
check_mode: yes
|
|
|
|
|
|
# Check results
|
|
|
|
- name: "stat foobarrc (must still be there)"
|
|
stat:
|
|
path: "{{ foobarrc }}"
|
|
register: diversion_4
|
|
|
|
- name: "stat foobarrc.distrib (must not exist)"
|
|
stat:
|
|
path: "{{ foobarrc_distrib }}"
|
|
register: diversion_5
|
|
|
|
- name: "assert that results of test 03 are as expected"
|
|
assert:
|
|
that:
|
|
- diversion_0 is changed
|
|
- diversion_1 is changed
|
|
- diversion_2 is not changed
|
|
- diversion_3 is not changed
|
|
- diversion_4.stat.exists
|
|
- diversion_4.stat.checksum == foobarrc_oldsha1
|
|
- not diversion_5.stat.exists
|
|
- diversion_0.diversion == diversion_1.diversion
|
|
- diversion_2.diversion == diversion_3.diversion
|
|
- diversion_0.commands == diversion_1.commands
|
|
- diversion_2.commands == diversion_3.commands
|
|
quiet: yes
|
|
|
|
- name: "remove foobarrc diversion"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
state: absent
|
|
|
|
|
|
################################################################################
|
|
# TEST 04: divert=/etc/foobarrc.ansible
|
|
|
|
- name: "create foobarrc diversion with defaults"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
|
|
|
|
- name: "update foobarrc divert path (check mode, must report a change)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
divert: "{{ foobarrc_ansible }}"
|
|
register: diversion_0
|
|
check_mode: yes
|
|
|
|
- name: "update foobarrc divert path (must report a change)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
divert: "{{ foobarrc_ansible }}"
|
|
register: diversion_1
|
|
|
|
|
|
- name: "update foobarrc divert path (must NOT report a change, idempotency)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
divert: "{{ foobarrc_ansible }}"
|
|
register: diversion_2
|
|
|
|
- name: "update foobarrc divert path (check mode, must NOT report a change, idempotency)"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
divert: "{{ foobarrc_ansible }}"
|
|
register: diversion_3
|
|
check_mode: yes
|
|
|
|
|
|
# Check results
|
|
|
|
- name: "stat foobarrc (must still be there)"
|
|
stat:
|
|
path: "{{ foobarrc }}"
|
|
register: diversion_4
|
|
|
|
- name: "stat foobarrc.ansible (must not exist)"
|
|
stat:
|
|
path: "{{ foobarrc_ansible }}"
|
|
register: diversion_5
|
|
|
|
- name: "assert that results of test 04 are as expected"
|
|
assert:
|
|
that:
|
|
- diversion_0 is changed
|
|
- diversion_1 is changed
|
|
- diversion_2 is not changed
|
|
- diversion_3 is not changed
|
|
- diversion_4.stat.exists
|
|
- diversion_4.stat.checksum == foobarrc_oldsha1
|
|
- not diversion_5.stat.exists
|
|
- diversion_0.diversion == diversion_1.diversion
|
|
- diversion_2.diversion == diversion_3.diversion
|
|
- diversion_0.commands == diversion_1.commands
|
|
- diversion_2.commands == diversion_3.commands
|
|
quiet: yes
|
|
|
|
- name: "remove foobarrc diversion"
|
|
dpkg_divert:
|
|
path: "{{ foobarrc }}"
|
|
state: absent
|