mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-05-07 05:43:26 +00:00
For failed_when result.failed should be used to make sure that the task fails if there was an error. For the duplicate names in hosts test failed_when: not result.failed has been added as this test needs to fail.
115 lines
3.2 KiB
YAML
115 lines
3.2 KiB
YAML
---
|
|
- name: Test hosts
|
|
hosts: ipaserver
|
|
become: true
|
|
|
|
tasks:
|
|
- name: Get Domain from server name
|
|
set_fact:
|
|
ipaserver_domain: "{{ ansible_facts['fqdn'].split('.')[1:] | join ('.') }}"
|
|
when: ipaserver_domain is not defined
|
|
|
|
- name: Set host1_fqdn .. host6_fqdn
|
|
set_fact:
|
|
host1_fqdn: "{{ 'host1.' + ipaserver_domain }}"
|
|
host2_fqdn: "{{ 'host2.' + ipaserver_domain }}"
|
|
host3_fqdn: "{{ 'host3.' + ipaserver_domain }}"
|
|
host4_fqdn: "{{ 'host4.' + ipaserver_domain }}"
|
|
host5_fqdn: "{{ 'host5.' + ipaserver_domain }}"
|
|
host6_fqdn: "{{ 'host6.' + ipaserver_domain }}"
|
|
|
|
- name: Host host1..host6 absent
|
|
ipahost:
|
|
ipaadmin_password: SomeADMINpassword
|
|
hosts:
|
|
- name: "{{ host1_fqdn }}"
|
|
- name: "{{ host2_fqdn }}"
|
|
- name: "{{ host3_fqdn }}"
|
|
- name: "{{ host4_fqdn }}"
|
|
- name: "{{ host5_fqdn }}"
|
|
- name: "{{ host6_fqdn }}"
|
|
state: absent
|
|
|
|
- name: Hosts host1..host6 present
|
|
ipahost:
|
|
ipaadmin_password: SomeADMINpassword
|
|
hosts:
|
|
- name: "{{ host1_fqdn }}"
|
|
force: yes
|
|
- name: "{{ host2_fqdn }}"
|
|
force: yes
|
|
- name: "{{ host3_fqdn }}"
|
|
force: yes
|
|
- name: "{{ host4_fqdn }}"
|
|
force: yes
|
|
- name: "{{ host5_fqdn }}"
|
|
force: yes
|
|
- name: "{{ host6_fqdn }}"
|
|
force: yes
|
|
register: result
|
|
failed_when: not result.changed or result.failed
|
|
|
|
- name: Hosts host1..host6 present again
|
|
ipahost:
|
|
ipaadmin_password: SomeADMINpassword
|
|
hosts:
|
|
- name: "{{ host1_fqdn }}"
|
|
force: yes
|
|
- name: "{{ host2_fqdn }}"
|
|
force: yes
|
|
- name: "{{ host3_fqdn }}"
|
|
force: yes
|
|
- name: "{{ host4_fqdn }}"
|
|
force: yes
|
|
- name: "{{ host5_fqdn }}"
|
|
force: yes
|
|
- name: "{{ host6_fqdn }}"
|
|
force: yes
|
|
register: result
|
|
failed_when: result.changed or result.failed
|
|
|
|
- name: Hosts host1..host6 absent
|
|
ipahost:
|
|
ipaadmin_password: SomeADMINpassword
|
|
hosts:
|
|
- name: "{{ host1_fqdn }}"
|
|
- name: "{{ host2_fqdn }}"
|
|
- name: "{{ host3_fqdn }}"
|
|
- name: "{{ host4_fqdn }}"
|
|
- name: "{{ host5_fqdn }}"
|
|
- name: "{{ host6_fqdn }}"
|
|
state: absent
|
|
register: result
|
|
failed_when: not result.changed or result.failed
|
|
|
|
- name: Hosts host1..host6 absent again
|
|
ipahost:
|
|
ipaadmin_password: SomeADMINpassword
|
|
hosts:
|
|
- name: "{{ host1_fqdn }}"
|
|
- name: "{{ host2_fqdn }}"
|
|
- name: "{{ host3_fqdn }}"
|
|
- name: "{{ host4_fqdn }}"
|
|
- name: "{{ host5_fqdn }}"
|
|
- name: "{{ host6_fqdn }}"
|
|
state: absent
|
|
register: result
|
|
failed_when: result.changed or result.failed
|
|
|
|
# Use failed_when: not result.failed as this test needs to fail because a
|
|
# host is added two times in the same task
|
|
- name: Duplicate names in hosts failure test
|
|
ipahost:
|
|
ipaadmin_password: SomeADMINpassword
|
|
hosts:
|
|
- name: "{{ host1_fqdn }}"
|
|
force: yes
|
|
- name: "{{ host2_fqdn }}"
|
|
force: yes
|
|
- name: "{{ host3_fqdn }}"
|
|
force: yes
|
|
- name: "{{ host3_fqdn }}"
|
|
force: yes
|
|
register: result
|
|
failed_when: result.changed or not result.failed or "is used more than once" not in result.msg
|