From d0287f90cd078a01c518dc7a2bbd65b1754fb405 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman <rjeffman@redhat.com> Date: Fri, 3 Sep 2021 13:28:28 -0300 Subject: [PATCH] ipahost: Allow execution of plugin in client host. Update host README file and add tests for executing plugin with `ipaapi_context` set to `client`. A new test playbook can be found at: tests/host/test_host_client_context.yml The new test file can be executed in a FreeIPA client host that is not a server. In this case, it should be defined in the `ipaclients` group, in the inventory file. --- README-host.md | 1 + tests/host/test_host.yml | 20 +++++++++++-- tests/host/test_host_client_context.yml | 37 +++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 tests/host/test_host_client_context.yml diff --git a/README-host.md b/README-host.md index 56c92bda..ba274c98 100644 --- a/README-host.md +++ b/README-host.md @@ -320,6 +320,7 @@ Variable | Description | Required -------- | ----------- | -------- `ipaadmin_principal` | The admin principal is a string and defaults to `admin` | no `ipaadmin_password` | The admin password is a string and is required if there is no admin ticket available on the node | no +`ipaapi_context` | The context in which the module will execute. Executing in a server context is preferred. If not provided context will be determined by the execution environment. Valid values are `server` and `client`. | no `name` \| `fqdn` | The list of host name strings. `name` with *host variables* or `hosts` containing *host variables* need to be used. | no **Host variables** | Only used with `name` variable in the first level. | no `hosts` | The list of host dicts. Each `hosts` dict entry can contain **host variables**.<br>There is one required option in the `hosts` dict:| no diff --git a/tests/host/test_host.yml b/tests/host/test_host.yml index 3b186525..bee85ef7 100644 --- a/tests/host/test_host.yml +++ b/tests/host/test_host.yml @@ -1,6 +1,6 @@ --- - name: Test host - hosts: ipaserver + hosts: "{{ ipa_test_host | default('ipaserver') }}" become: true tasks: @@ -21,6 +21,7 @@ - name: Host absent ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: - "{{ host1_fqdn }}" - "{{ host2_fqdn }}" @@ -39,6 +40,7 @@ - name: Host "{{ host1_fqdn }}" present ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ host1_fqdn }}" ip_address: "{{ ipv4_prefix + '.201' }}" update_dns: yes @@ -49,6 +51,7 @@ - name: Host "{{ host1_fqdn }}" present again ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ host1_fqdn }}" ip_address: "{{ ipv4_prefix + '.201' }}" update_dns: yes @@ -59,6 +62,7 @@ - name: Host "{{ host2_fqdn }}" present ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ host2_fqdn }}" ip_address: "{{ ipv4_prefix + '.202' }}" update_dns: yes @@ -69,6 +73,7 @@ - name: Host "{{ host2_fqdn }}" present again ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ host2_fqdn }}" ip_address: "{{ ipv4_prefix + '.202' }}" update_dns: yes @@ -79,6 +84,7 @@ - name: Host "{{ host3_fqdn }}" present ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ host3_fqdn }}" ip_address: "{{ ipv4_prefix + '.203' }}" update_dns: yes @@ -89,6 +95,7 @@ - name: Host "{{ host3_fqdn }}" present again ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ host3_fqdn }}" ip_address: "{{ ipv4_prefix + '.203' }}" update_dns: yes @@ -99,6 +106,7 @@ - name: Host "{{ host4_fqdn }}" present ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ host4_fqdn }}" ip_address: "{{ ipv4_prefix + '.204' }}" update_dns: yes @@ -109,6 +117,7 @@ - name: Host "{{ host4_fqdn }}" present again ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ host4_fqdn }}" ip_address: "{{ ipv4_prefix + '.204' }}" update_dns: yes @@ -119,6 +128,7 @@ - name: Host "{{ host5_fqdn }}" present ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ host5_fqdn }}" ip_address: "{{ ipv4_prefix + '.205' }}" update_dns: yes @@ -129,6 +139,7 @@ - name: Host "{{ host5_fqdn }}" present again ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ host5_fqdn }}" ip_address: "{{ ipv4_prefix + '.205' }}" update_dns: yes @@ -139,6 +150,7 @@ - name: Host "{{ host6_fqdn }}" present ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ host6_fqdn }}" ip_address: "{{ ipv4_prefix + '.206' }}" update_dns: yes @@ -149,6 +161,7 @@ - name: Host "{{ host6_fqdn }}" present again ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ host6_fqdn }}" ip_address: "{{ ipv4_prefix + '.206' }}" update_dns: yes @@ -161,6 +174,7 @@ #- name: Hosts host1..host6 disabled # ipahost: # ipaadmin_password: SomeADMINpassword + # ipaapi_context: "{{ ipa_context | default(omit) }}" # name: # - "{{ host1_fqdn }}" # - "{{ host2_fqdn }}" @@ -175,6 +189,7 @@ #- name: Hosts host1..host6 disabled again # ipahost: # ipaadmin_password: SomeADMINpassword + # ipaapi_context: "{{ ipa_context | default(omit) }}" # name: # - "{{ host1_fqdn }}" # - "{{ host2_fqdn }}" @@ -189,6 +204,7 @@ - name: Hosts host1..host6 absent ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: - "{{ host1_fqdn }}" - "{{ host2_fqdn }}" @@ -204,6 +220,7 @@ - name: Hosts host1..host6 absent again ipahost: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: - "{{ host1_fqdn }}" - "{{ host2_fqdn }}" @@ -215,4 +232,3 @@ state: absent register: result failed_when: result.changed or result.failed - diff --git a/tests/host/test_host_client_context.yml b/tests/host/test_host_client_context.yml new file mode 100644 index 00000000..ba307401 --- /dev/null +++ b/tests/host/test_host_client_context.yml @@ -0,0 +1,37 @@ +--- +- name: Test host + hosts: ipaclients, ipaserver + 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. + ipahost: + 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 automember using client context, in client host. + import_playbook: test_host.yml + when: groups['ipaclients'] + vars: + ipa_test_host: ipaclients + +- name: Test automember using client context, in server host. + import_playbook: test_host.yml + when: groups['ipaclients'] is not defined or not groups['ipaclients'] -- GitLab