From 1c8f1c28e1409bb6a6c30ed52923fb54256cce5c Mon Sep 17 00:00:00 2001 From: Thomas Woerner <twoerner@redhat.com> Date: Wed, 12 Apr 2023 13:11:50 +0200 Subject: [PATCH] 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 --- utils/templates/test_module+member.yml.in | 23 ++++------------------- utils/templates/test_module.yml.in | 14 ++++---------- 2 files changed, 8 insertions(+), 29 deletions(-) diff --git a/utils/templates/test_module+member.yml.in b/utils/templates/test_module+member.yml.in index e92ac9f4..5517b6ae 100644 --- a/utils/templates/test_module+member.yml.in +++ b/utils/templates/test_module+member.yml.in @@ -6,6 +6,10 @@ 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: @@ -13,7 +17,6 @@ - name: Ensure $name NAME is absent ipa$name: - ipaadmin_password: SomeADMINpassword name: NAME state: absent @@ -23,8 +26,6 @@ - name: Ensure $name NAME is present ipa$name: - ipaadmin_password: SomeADMINpassword - ipaapi_context: "{{ ipa_context | default(omit) }}" name: NAME # Add needed parameters here register: result @@ -32,8 +33,6 @@ - name: Ensure $name NAME is present again ipa$name: - ipaadmin_password: SomeADMINpassword - ipaapi_context: "{{ ipa_context | default(omit) }}" name: NAME # Add needed parameters here register: result @@ -41,8 +40,6 @@ - name: Ensure $name NAME member PARAMETER2 VALUE is present ipa$name: - ipaadmin_password: SomeADMINpassword - ipaapi_context: "{{ ipa_context | default(omit) }}" name: NAME PARAMETER2: VALUE action: member @@ -51,8 +48,6 @@ - name: Ensure $name NAME member PARAMETER2 VALUE is present again ipa$name: - ipaadmin_password: SomeADMINpassword - ipaapi_context: "{{ ipa_context | default(omit) }}" name: NAME PARAMETER2: VALUE action: member @@ -61,8 +56,6 @@ - name: Ensure $name NAME member PARAMETER2 VALUE is absent ipa$name: - ipaadmin_password: SomeADMINpassword - ipaapi_context: "{{ ipa_context | default(omit) }}" name: NAME PARAMETER2: VALUE action: member @@ -72,8 +65,6 @@ - name: Ensure $name NAME member PARAMETER2 VALUE is absent again ipa$name: - ipaadmin_password: SomeADMINpassword - ipaapi_context: "{{ ipa_context | default(omit) }}" name: NAME PARAMETER2: VALUE action: member @@ -85,8 +76,6 @@ - name: Ensure $name NAME is absent ipa$name: - ipaadmin_password: SomeADMINpassword - ipaapi_context: "{{ ipa_context | default(omit) }}" name: NAME state: absent register: result @@ -94,8 +83,6 @@ - name: Ensure $name NAME is absent again ipa$name: - ipaadmin_password: SomeADMINpassword - ipaapi_context: "{{ ipa_context | default(omit) }}" name: NAME state: absent register: result @@ -105,7 +92,5 @@ - name: Ensure $name NAME is absent ipa$name: - ipaadmin_password: SomeADMINpassword - ipaapi_context: "{{ ipa_context | default(omit) }}" name: NAME state: absent diff --git a/utils/templates/test_module.yml.in b/utils/templates/test_module.yml.in index 62e0a79b..f135cfd0 100644 --- a/utils/templates/test_module.yml.in +++ b/utils/templates/test_module.yml.in @@ -6,6 +6,10 @@ 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: @@ -13,8 +17,6 @@ - name: Ensure $name NAME is absent ipa$name: - ipaadmin_password: SomeADMINpassword - ipaapi_context: "{{ ipa_context | default(omit) }}" name: NAME state: absent @@ -24,7 +26,6 @@ - name: Ensure $name NAME is present ipa$name: - ipaadmin_password: SomeADMINpassword name: NAME # Add needed parameters here register: result @@ -32,8 +33,6 @@ - name: Ensure $name NAME is present again ipa$name: - ipaadmin_password: SomeADMINpassword - ipaapi_context: "{{ ipa_context | default(omit) }}" name: NAME # Add needed parameters here register: result @@ -43,8 +42,6 @@ - name: Ensure $name NAME is absent ipa$name: - ipaadmin_password: SomeADMINpassword - ipaapi_context: "{{ ipa_context | default(omit) }}" name: NAME state: absent register: result @@ -52,8 +49,6 @@ - name: Ensure $name NAME is absent again ipa$name: - ipaadmin_password: SomeADMINpassword - ipaapi_context: "{{ ipa_context | default(omit) }}" name: NAME state: absent register: result @@ -63,6 +58,5 @@ - name: Ensure $name NAME is absent ipa$name: - ipaadmin_password: SomeADMINpassword name: NAME state: absent -- GitLab