From d2bcaa3b81849b644d470405b4ff4bb6645f3e18 Mon Sep 17 00:00:00 2001
From: Rafael Guterres Jeffman <rjeffman@redhat.com>
Date: Fri, 12 Nov 2021 18:02:25 -0300
Subject: [PATCH] test playbooks: Add fact to define ipaserver_domain if not
 set.

Add a task to FreeIPA facts task file to ensure that the variable
'ipaserver_domain' is set.

The value is set form `ansible_facts['fqdn'], if available, or set to
`ipa.test`, otherwise.
---
 tests/env_freeipa_facts.yml | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tests/env_freeipa_facts.yml b/tests/env_freeipa_facts.yml
index a150ecd6..0ab8541e 100644
--- a/tests/env_freeipa_facts.yml
+++ b/tests/env_freeipa_facts.yml
@@ -29,3 +29,15 @@
     ipa_api_version: "{{ ipa_cmd_version.stdout_lines[1] }}"
     ipa_host_is_client: "{{ (output.stdout_lines[-1] == 'CLIENT') | bool }}"
     trust_test_is_supported: no
+
+- block:
+  - name: Get Domain from server name
+    set_fact:
+      ipaserver_domain: "{{ ansible_facts['fqdn'].split('.')[1:] | join ('.') }}"
+    when: "'fqdn' in ansible_facts"
+
+  - name: Set Domain to 'ipa.test' if FQDN could not be retrieved.
+    set_fact:
+      ipaserver_domain: "ipa.test"
+    when: "'fqdn' not in ansible_facts"
+  when: ipaserver_domain is not defined
-- 
GitLab