diff --git a/README-server.md b/README-server.md index b899cdaca02141e60b55018deb6717600c987f7b..66e62bb53188bb8416ede9e4900bf2081aa29dfa 100644 --- a/README-server.md +++ b/README-server.md @@ -230,6 +230,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` | The list of server name strings. | yes `location` \| `ipalocation_location` | The server location string. Only in state: present. "" for location reset. | no `service_weight` \| `ipaserviceweight` | Weight for server services. Type Values 0 to 65535, -1 for weight reset. Only in state: present. (int) | no diff --git a/tests/server/test_server.yml b/tests/server/test_server.yml index b7f0193aacf5464626b276c0e96be86f68970624..0f97b2ac56bd97f8b7f0c0fa2afa866a1ad6fc0a 100644 --- a/tests/server/test_server.yml +++ b/tests/server/test_server.yml @@ -1,6 +1,6 @@ --- - name: Test server - hosts: ipaserver + hosts: "{{ ipa_test_host | default('ipaserver') }}" become: true gather_facts: yes @@ -30,18 +30,21 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without location ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" location: "" - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without service weight ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" service_weight: -1 - name: Ensure location "mylocation" is absent ipalocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: mylocation state: absent @@ -50,6 +53,7 @@ - name: Ensure location "mylocation" is present ipalocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: mylocation register: result failed_when: not result.changed or result.failed @@ -59,6 +63,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" is present ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" register: result failed_when: result.changed or result.failed @@ -66,6 +71,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with location "mylocation" ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" location: "mylocation" register: result @@ -74,6 +80,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with location "mylocation" again ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" location: "mylocation" register: result @@ -82,6 +89,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without location ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" location: "" register: result @@ -90,6 +98,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without location again ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" location: "" register: result @@ -98,6 +107,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with service weight 1 ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" service_weight: 1 register: result @@ -106,6 +116,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with service weight 1 again ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" service_weight: 1 register: result @@ -114,6 +125,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without service weight ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" service_weight: -1 register: result @@ -122,6 +134,7 @@ - name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without service weight again ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ ipa_server_name + '.' + ipaserver_domain }}" service_weight: -1 register: result @@ -134,6 +147,7 @@ - name: Ensure server "{{ 'absent.' + ipaserver_domain }}" is absent ipaserver: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: "{{ 'absent.' + ipaserver_domain }}" state: absent register: result @@ -148,6 +162,7 @@ - name: Ensure location "mylocation" is absent ipalocation: ipaadmin_password: SomeADMINpassword + ipaapi_context: "{{ ipa_context | default(omit) }}" name: mylocation state: absent register: result diff --git a/tests/server/test_server_client_context.yml b/tests/server/test_server_client_context.yml new file mode 100644 index 0000000000000000000000000000000000000000..d1f310900106b95fbd8223528423ddc2537e596d --- /dev/null +++ b/tests/server/test_server_client_context.yml @@ -0,0 +1,37 @@ +--- +- name: Test server + 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. + ipaserver: + 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 server using client context, in client host. + import_playbook: test_server.yml + when: groups['ipaclients'] + vars: + ipa_test_host: ipaclients + +- name: Test server using client context, in server host. + import_playbook: test_server.yml + when: groups['ipaclients'] is not defined or not groups['ipaclients']