mirror of
https://github.com/freeipa/ansible-freeipa.git
synced 2026-07-31 11:54:47 +00:00
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'.
This commit is contained in:
@@ -2,21 +2,41 @@
|
|||||||
- name: Test server
|
- name: Test server
|
||||||
hosts: ipaserver
|
hosts: ipaserver
|
||||||
become: true
|
become: true
|
||||||
|
gather_facts: yes
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
|
||||||
# CLEANUP TEST ITEMS
|
# 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
|
||||||
|
|
||||||
- name: Ensure server "{{ 'ipaserver.' + ipaserver_domain }}" without location
|
- 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:
|
ipaserver:
|
||||||
ipaadmin_password: SomeADMINpassword
|
ipaadmin_password: SomeADMINpassword
|
||||||
name: "{{ 'ipaserver.' + ipaserver_domain }}"
|
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
|
||||||
location: ""
|
location: ""
|
||||||
|
|
||||||
- name: Ensure server "{{ 'ipaserver.' + ipaserver_domain }}" without service weight
|
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without service weight
|
||||||
ipaserver:
|
ipaserver:
|
||||||
ipaadmin_password: SomeADMINpassword
|
ipaadmin_password: SomeADMINpassword
|
||||||
name: "{{ 'ipaserver.' + ipaserver_domain }}"
|
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
|
||||||
service_weight: -1
|
service_weight: -1
|
||||||
|
|
||||||
- name: Ensure location "mylocation" is absent
|
- name: Ensure location "mylocation" is absent
|
||||||
@@ -36,73 +56,73 @@
|
|||||||
|
|
||||||
# TESTS
|
# TESTS
|
||||||
|
|
||||||
- name: Ensure server "{{ 'ipaserver.' + ipaserver_domain }}" is present
|
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" is present
|
||||||
ipaserver:
|
ipaserver:
|
||||||
ipaadmin_password: SomeADMINpassword
|
ipaadmin_password: SomeADMINpassword
|
||||||
name: "{{ 'ipaserver.' + ipaserver_domain }}"
|
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
|
||||||
register: result
|
register: result
|
||||||
failed_when: result.changed or result.failed
|
failed_when: result.changed or result.failed
|
||||||
|
|
||||||
- name: Ensure server "{{ 'ipaserver.' + ipaserver_domain }}" with location "mylocation"
|
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with location "mylocation"
|
||||||
ipaserver:
|
ipaserver:
|
||||||
ipaadmin_password: SomeADMINpassword
|
ipaadmin_password: SomeADMINpassword
|
||||||
name: "{{ 'ipaserver.' + ipaserver_domain }}"
|
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
|
||||||
location: "mylocation"
|
location: "mylocation"
|
||||||
register: result
|
register: result
|
||||||
failed_when: not result.changed or result.failed
|
failed_when: not result.changed or result.failed
|
||||||
|
|
||||||
- name: Ensure server "{{ 'ipaserver.' + ipaserver_domain }}" with location "mylocation" again
|
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with location "mylocation" again
|
||||||
ipaserver:
|
ipaserver:
|
||||||
ipaadmin_password: SomeADMINpassword
|
ipaadmin_password: SomeADMINpassword
|
||||||
name: "{{ 'ipaserver.' + ipaserver_domain }}"
|
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
|
||||||
location: "mylocation"
|
location: "mylocation"
|
||||||
register: result
|
register: result
|
||||||
failed_when: result.changed or result.failed
|
failed_when: result.changed or result.failed
|
||||||
|
|
||||||
- name: Ensure server "{{ 'ipaserver.' + ipaserver_domain }}" without location
|
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without location
|
||||||
ipaserver:
|
ipaserver:
|
||||||
ipaadmin_password: SomeADMINpassword
|
ipaadmin_password: SomeADMINpassword
|
||||||
name: "{{ 'ipaserver.' + ipaserver_domain }}"
|
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
|
||||||
location: ""
|
location: ""
|
||||||
register: result
|
register: result
|
||||||
failed_when: not result.changed or result.failed
|
failed_when: not result.changed or result.failed
|
||||||
|
|
||||||
- name: Ensure server "{{ 'ipaserver.' + ipaserver_domain }}" without location again
|
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without location again
|
||||||
ipaserver:
|
ipaserver:
|
||||||
ipaadmin_password: SomeADMINpassword
|
ipaadmin_password: SomeADMINpassword
|
||||||
name: "{{ 'ipaserver.' + ipaserver_domain }}"
|
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
|
||||||
location: ""
|
location: ""
|
||||||
register: result
|
register: result
|
||||||
failed_when: result.changed or result.failed
|
failed_when: result.changed or result.failed
|
||||||
|
|
||||||
- name: Ensure server "{{ 'ipaserver.' + ipaserver_domain }}" with service weight 1
|
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with service weight 1
|
||||||
ipaserver:
|
ipaserver:
|
||||||
ipaadmin_password: SomeADMINpassword
|
ipaadmin_password: SomeADMINpassword
|
||||||
name: "{{ 'ipaserver.' + ipaserver_domain }}"
|
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
|
||||||
service_weight: 1
|
service_weight: 1
|
||||||
register: result
|
register: result
|
||||||
failed_when: not result.changed or result.failed
|
failed_when: not result.changed or result.failed
|
||||||
|
|
||||||
- name: Ensure server "{{ 'ipaserver.' + ipaserver_domain }}" with service weight 1 again
|
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" with service weight 1 again
|
||||||
ipaserver:
|
ipaserver:
|
||||||
ipaadmin_password: SomeADMINpassword
|
ipaadmin_password: SomeADMINpassword
|
||||||
name: "{{ 'ipaserver.' + ipaserver_domain }}"
|
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
|
||||||
service_weight: 1
|
service_weight: 1
|
||||||
register: result
|
register: result
|
||||||
failed_when: result.changed or result.failed
|
failed_when: result.changed or result.failed
|
||||||
|
|
||||||
- name: Ensure server "{{ 'ipaserver.' + ipaserver_domain }}" without service weight
|
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without service weight
|
||||||
ipaserver:
|
ipaserver:
|
||||||
ipaadmin_password: SomeADMINpassword
|
ipaadmin_password: SomeADMINpassword
|
||||||
name: "{{ 'ipaserver.' + ipaserver_domain }}"
|
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
|
||||||
service_weight: -1
|
service_weight: -1
|
||||||
register: result
|
register: result
|
||||||
failed_when: not result.changed or result.failed
|
failed_when: not result.changed or result.failed
|
||||||
|
|
||||||
- name: Ensure server "{{ 'ipaserver.' + ipaserver_domain }}" without service weight again
|
- name: Ensure server "{{ ipa_server_name + '.' + ipaserver_domain }}" without service weight again
|
||||||
ipaserver:
|
ipaserver:
|
||||||
ipaadmin_password: SomeADMINpassword
|
ipaadmin_password: SomeADMINpassword
|
||||||
name: "{{ 'ipaserver.' + ipaserver_domain }}"
|
name: "{{ ipa_server_name + '.' + ipaserver_domain }}"
|
||||||
service_weight: -1
|
service_weight: -1
|
||||||
register: result
|
register: result
|
||||||
failed_when: result.changed or result.failed
|
failed_when: result.changed or result.failed
|
||||||
|
|||||||
Reference in New Issue
Block a user