Files
ansible-freeipa/utils/templates/test_module.yml.in
Thomas Woerner 1c8f1c28e1 utils/templates/test_module*.yml.in: Use generic module_defaults
The usage of module_defaults allows to reduce the size of the tests and
to have the needed information in the tasks only. The default values for the
parameters are automatically passed to the module by Ansible.

It is not possible to use a module group for module_defaults as this could
only be done with Ansible Collections. The tests are also used upstream and
downstream without a collection.

Without groups of a collection it is needed to add the defaults for all
modules separately.

Simple example:

    module_defaults:
      ipahost:
        ipaadmin_password: SomeADMINpassword
        ipaapi_context: "{{ ipa_context | default(omit) }}"

Several module example using YAML anchors and aliases:

    module_defaults:
      ipahost: &ipa_module_defaults
        ipaadmin_password: SomeADMINpassword
        ipaapi_context: "{{ ipa_context | default(omit) }}"
      ipauser: *ipa_module_defaults
      ipagroup: *ipa_module_defaults
2023-04-20 10:10:51 +02:00

63 lines
1.4 KiB
YAML

---
- name: Test $name
hosts: "{{ ipa_test_host | default('ipaserver') }}"
# It is normally not needed to set "become" to "true" for a module test.
# Only set it to true if it is needed to execute commands as root.
become: false
# Enable "gather_facts" only if "ansible_facts" variable needs to be used.
gather_facts: false
module_defaults:
ipa$name:
ipaadmin_password: SomeADMINpassword
ipaapi_context: "{{ ipa_context | default(omit) }}"
tasks:
# CLEANUP TEST ITEMS
- name: Ensure $name NAME is absent
ipa$name:
name: NAME
state: absent
# CREATE TEST ITEMS
# TESTS
- name: Ensure $name NAME is present
ipa$name:
name: NAME
# Add needed parameters here
register: result
failed_when: not result.changed or result.failed
- name: Ensure $name NAME is present again
ipa$name:
name: NAME
# Add needed parameters here
register: result
failed_when: result.changed or result.failed
# more tests here
- name: Ensure $name NAME is absent
ipa$name:
name: NAME
state: absent
register: result
failed_when: not result.changed or result.failed
- name: Ensure $name NAME is absent again
ipa$name:
name: NAME
state: absent
register: result
failed_when: result.changed or result.failed
# CLEANUP TEST ITEMS
- name: Ensure $name NAME is absent
ipa$name:
name: NAME
state: absent