diff --git a/README-automountlocation.md b/README-automountlocation.md index f28afc2ac73e5543fe90254c5848a9ebb4869887..42393bc163ab635348ab86833e04256a0e859ea9 100644 --- a/README-automountlocation.md +++ b/README-automountlocation.md @@ -88,7 +88,7 @@ Example playbook to ensure absence of an automount location: - name: ensure automount locations LOCATION1 and LOCATION2 do not exist ipaautomountlocation: ipaadmin_password: SomeADMINpassword - name: + name: - LOCATION1 - LOCATION2 state: absent @@ -104,6 +104,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` \| `cn` \| `location` | List of one or more automountlocation names. | yes `state` | The state to ensure. It can be one of `present`, or `absent`, default: `present`. | no diff --git a/tests/automount/test_automountlocation.yml b/tests/automount/test_automountlocation.yml index 1eb11a65de10c2288f4c5fa83f77afed24eefead..7e6c3abb9788c18a4b6ae6fd0c772c8f3e8a8fd3 100644 --- a/tests/automount/test_automountlocation.yml +++ b/tests/automount/test_automountlocation.yml @@ -1,6 +1,6 @@ --- - name: Test automountlocation - hosts: ipaserver + hosts: "{{ ipa_test_host | default('ipaserver') }}" become: true gather_facts: false @@ -8,6 +8,7 @@ - name: ensure automountlocation TestLocations are absent before testing ipaautomountlocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: - TestLocation_01 - TestLocation_02 @@ -16,6 +17,7 @@ - name: ensure empty automountlocation does nothing ipaautomountlocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: [] state: present register: result @@ -24,6 +26,7 @@ - name: ensure empty automountlocation does nothing on absent ipaautomountlocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: [] state: absent register: result @@ -32,6 +35,7 @@ - name: ensure automountlocation TestLocation is present ipaautomountlocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: TestLocation_01 state: present register: result @@ -40,6 +44,7 @@ - name: ensure automountlocation TestLocation is present again ipaautomountlocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: TestLocation_01 state: present register: result @@ -48,6 +53,7 @@ - name: ensure automountlocation TestLocation is absent ipaautomountlocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: TestLocation_01 state: absent register: result @@ -56,6 +62,7 @@ - name: ensure automountlocation TestLocation is absent again ipaautomountlocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: TestLocation_01 state: absent register: result @@ -64,6 +71,7 @@ - name: ensure a list of automountlocations are present ipaautomountlocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: - TestLocation_01 - TestLocation_02 @@ -74,6 +82,7 @@ - name: ensure a list of automountlocations exist ipaautomountlocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: - TestLocation_01 - TestLocation_02 @@ -84,6 +93,7 @@ - name: ensure a list of automountlocations are absent ipaautomountlocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: - TestLocation_01 - TestLocation_02 @@ -94,6 +104,7 @@ - name: ensure multiple automountlocations are absent ipaautomountlocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: - TestLocation_01 - TestLocation_02 diff --git a/tests/automount/test_automountlocation_client_context.yml b/tests/automount/test_automountlocation_client_context.yml new file mode 100644 index 0000000000000000000000000000000000000000..ac5341408d6068e3a38af10a8000ec40ca85e6a5 --- /dev/null +++ b/tests/automount/test_automountlocation_client_context.yml @@ -0,0 +1,37 @@ +--- +- name: Test automountlocation + 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. + ipaautomountlocation: + 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 automountlocation using client context, in client host. + import_playbook: test_automountlocation.yml + when: groups['ipaclients'] + vars: + ipa_test_host: ipaclients + +- name: Test automountlocation using client context, in server host. + import_playbook: test_automountlocation.yml + when: groups['ipaclients'] is not defined or not groups['ipaclients']