Files
ansible-freeipa/tests/server/test_server.yml
Rafael Guterres Jeffman 076835e008 ipaserver: Allow configuration of test server name.
As the server name was hard coded, when running tests for ipasever
module using a server not name as 'ipaserver', the tests would fail.

This patch allows the configuration of the server name using the
variable 'ipa_server_name', and if not provided, try to infer the name
from the ansible_hostname variable, or, if not possible, defaults to
'ipaserver'.

The same behavior is applied to 'ipasever_domain', with the default
being 'ipa.test'.
2021-09-20 11:05:03 -03:00

155 lines
5.0 KiB
YAML

---
- name: Test server
hosts: ipaserver
become: true
gather_facts: yes
tasks:
# CLEANUP TEST ITEMS
- block:
- name: Get server name from hostname
set_fact:
ipa_server_name: "{{ ansible_facts['hostname'].split('.')[0] }}"
rescue:
- name: Fallback to 'ipaserver'
set_fact:
ipa_server_name: ipaserver
when: ipa_server_name is not defined
- block:
- name: Get domain name from hostname.
set_fact:
ipaserver_domain: "{{ ansible_facts['hostname'].split('.')[0][1:] }}"
rescue:
- name: Fallback to 'ipa.test'
set_fact:
ipaserver_domain: "ipa.test"
when: ipaserver_domain is not defined
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without location
ipaserver:
ipaadmin_password: SomeADMINpassword
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
location: ""
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without service weight
ipaserver:
ipaadmin_password: SomeADMINpassword
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
service_weight: -1
- name: Ensure location "mylocation" is absent
ipalocation:
ipaadmin_password: SomeADMINpassword
name: mylocation
state: absent
# CREATE TEST ITEMS
- name: Ensure location "mylocation" is present
ipalocation:
ipaadmin_password: SomeADMINpassword
name: mylocation
register: result
failed_when: not result.changed or result.failed
# TESTS
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" is present
ipaserver:
ipaadmin_password: SomeADMINpassword
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
register: result
failed_when: result.changed or result.failed
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with location "mylocation"
ipaserver:
ipaadmin_password: SomeADMINpassword
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
location: "mylocation"
register: result
failed_when: not result.changed or result.failed
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with location "mylocation" again
ipaserver:
ipaadmin_password: SomeADMINpassword
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
location: "mylocation"
register: result
failed_when: result.changed or result.failed
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without location
ipaserver:
ipaadmin_password: SomeADMINpassword
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
location: ""
register: result
failed_when: not result.changed or result.failed
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without location again
ipaserver:
ipaadmin_password: SomeADMINpassword
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
location: ""
register: result
failed_when: result.changed or result.failed
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with service weight 1
ipaserver:
ipaadmin_password: SomeADMINpassword
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
service_weight: 1
register: result
failed_when: not result.changed or result.failed
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with service weight 1 again
ipaserver:
ipaadmin_password: SomeADMINpassword
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
service_weight: 1
register: result
failed_when: result.changed or result.failed
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without service weight
ipaserver:
ipaadmin_password: SomeADMINpassword
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
service_weight: -1
register: result
failed_when: not result.changed or result.failed
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without service weight again
ipaserver:
ipaadmin_password: SomeADMINpassword
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
service_weight: -1
register: result
failed_when: result.changed or result.failed
# hidden requires an additional server, not tested
# absent requires an additional server, only sanity test with absent server
- name: Ensure server "{{ 'absent.' + ipaserver_domain }}" is absent
ipaserver:
ipaadmin_password: SomeADMINpassword
name: "{{ 'absent.' + ipaserver_domain }}"
state: absent
register: result
failed_when: result.changed or result.failed
# ignore_last_of_role requires an additional server, not tested
# ignore_topology_disconnect requires an additional server, not tested
# CLEANUP TEST ITEMS
- name: Ensure location "mylocation" is absent
ipalocation:
ipaadmin_password: SomeADMINpassword
name: mylocation
state: absent
register: result
failed_when: not result.changed or result.failed