templates: Allow execution of plugins in an IPA client host.

Modify templates to create the basic tests for `ipaapi_context: client`.
This commit is contained in:
Rafael Guterres Jeffman
2021-09-08 17:06:37 -03:00
parent 8bc6b01f49
commit 1c679c5a9a
4 changed files with 61 additions and 2 deletions

View File

@@ -183,3 +183,4 @@ mkdir -p $dest
src=test_module.yml.in
[ $member == 1 ] && src=test_module+member.yml.in
template $src $dest/test_$name.yml
template test_module_client_context.yml.in $dest/test_${name}_client_context.yml

View File

@@ -1,7 +1,10 @@
---
- name: Test $name
hosts: ipaserver
hosts: "{{ ipa_test_host | default('ipaserver') }}"
# Change "become" or "gather_facts" to "yes",
# if you test playbook requires any.
become: no
gather_facts: no
tasks:
@@ -20,6 +23,7 @@
- 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
@@ -28,6 +32,7 @@
- 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
@@ -36,6 +41,7 @@
- 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
@@ -45,6 +51,7 @@
- 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
@@ -54,6 +61,7 @@
- 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
@@ -64,6 +72,7 @@
- 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
@@ -76,6 +85,7 @@
- name: Ensure $name NAME is absent
ipa$name:
ipaadmin_password: SomeADMINpassword
ipaapi_context: "{{ ipa_context | default(omit) }}"
name: NAME
state: absent
register: result
@@ -84,6 +94,7 @@
- name: Ensure $name NAME is absent again
ipa$name:
ipaadmin_password: SomeADMINpassword
ipaapi_context: "{{ ipa_context | default(omit) }}"
name: NAME
state: absent
register: result
@@ -94,5 +105,6 @@
- name: Ensure $name NAME is absent
ipa$name:
ipaadmin_password: SomeADMINpassword
ipaapi_context: "{{ ipa_context | default(omit) }}"
name: NAME
state: absent

View File

@@ -1,7 +1,10 @@
---
- name: Test $name
hosts: ipaserver
hosts: "{{ ipa_test_host | default('ipaserver') }}"
# Change "become" or "gather_facts" to "yes",
# if you test playbook requires any.
become: no
gather_facts: no
tasks:
@@ -10,6 +13,7 @@
- name: Ensure $name NAME is absent
ipa$name:
ipaadmin_password: SomeADMINpassword
ipaapi_context: "{{ ipa_context | default(omit) }}"
name: NAME
state: absent
@@ -28,6 +32,7 @@
- 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
@@ -38,6 +43,7 @@
- name: Ensure $name NAME is absent
ipa$name:
ipaadmin_password: SomeADMINpassword
ipaapi_context: "{{ ipa_context | default(omit) }}"
name: NAME
state: absent
register: result
@@ -46,6 +52,7 @@
- name: Ensure $name NAME is absent again
ipa$name:
ipaadmin_password: SomeADMINpassword
ipaapi_context: "{{ ipa_context | default(omit) }}"
name: NAME
state: absent
register: result

View File

@@ -0,0 +1,39 @@
---
- name: Test ${name}
hosts: ipaclients, ipaserver
# Change "become" or "gather_facts" to "yes",
# if you test playbook requires any.
become: no
gather_facts: no
tasks:
- name: Include FreeIPA facts.
include_tasks: ../env_freeipa_facts.yml
# Test will only be executed if host is not a server.
- name: Execute with server context in the client.
ipa${name}:
ipaadmin_password: SomeADMINpassword
ipaapi_context: server
name: ThisShouldNotWork
register: result
failed_when: not (result.failed and result.msg is regex("No module named '*ipaserver'*"))
when: ipa_host_is_client
# Import basic module tests, and execute with ipa_context set to 'client'.
# If ipaclients is set, it will be executed using the client, if not,
# ipaserver will be used.
#
# With this setup, tests can be executed against an IPA client, against
# an IPA server using "client" context, and ensure that tests are executed
# in upstream CI.
- name: Test ${name} using client context, in client host.
import_playbook: test_${name}.yml
when: groups['ipaclients']
vars:
ipa_test_host: ipaclients
- name: Test ${name} using client context, in server host.
import_playbook: test_${name}.yml
when: groups['ipaclients'] is not defined or not groups['ipaclients']