Skip to content

Commit e0e2a7e

Browse files
committed
Check an FQDN is set
An FQDN should be set, and a validation is added to check. The validation can be disabled with the edpm_nodes_validation_check_for_fqdn variable. The molecule prepare.yml is updated to set a hostname so that the check passes. The existing validation that validates the FQDN is set in /etc/hosts is updated to use a new variable, edpm_nodes_validation_validate_fqdn_hosts_file, for the location of the hosts file so that the molecule test can still run and pass using a test hosts file at /tmp/hosts. Jira: https://issues.redhat.com/browse/OSPRH-6187 Jira: https://issues.redhat.com/browse/OSPRH-16536 Signed-off-by: James Slagle <[email protected]>
1 parent 9bb6038 commit e0e2a7e

File tree

5 files changed

+35
-2
lines changed

5 files changed

+35
-2
lines changed

roles/edpm_nodes_validation/defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ edpm_nodes_validation_hide_sensitive_logs: true
2222
edpm_nodes_validation_ping_test_ips: []
2323
edpm_nodes_validation_validate_controllers_icmp: true
2424
edpm_nodes_validation_validate_fqdn: false
25+
edpm_nodes_validation_validate_fqdn_hosts_file: /etc/hosts
26+
edpm_nodes_validation_check_for_fqdn: true
2527
edpm_nodes_validation_validate_gateway_icmp: true
2628
edpm_nodes_validation_ping_test_gateway_ips: []

roles/edpm_nodes_validation/meta/argument_specs.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@ argument_specs:
1616
description: Attempt to reach controllers with ping.
1717
type: bool
1818
default: true
19+
edpm_nodes_validation_check_for_fqdn:
20+
description: Verify if an FQDN is set. Typically required for TLS-e.
21+
type: bool
22+
default: true
1923
edpm_nodes_validation_validate_fqdn:
2024
description: Verify if hostname matches FQDN from /etc/hosts
2125
type: bool
2226
default: false
27+
edpm_nodes_validation_validate_fqdn_hosts_file:
28+
description: Hosts file to check for verifying that hostname matches FQDN
29+
type: str
30+
default: /etc/hosts
2331
edpm_nodes_validation_validate_gateway_icmp:
2432
description: Attempt to reach gateway with ping.
2533
type: bool

roles/edpm_nodes_validation/molecule/default/prepare.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,12 @@
2626
ansible.builtin.dnf:
2727
name: hostname
2828
state: present
29+
- name: Set a FQDN
30+
command: hostname instance.localdomain
31+
- name: Add FQDN to /tmp/hosts
32+
lineinfile:
33+
path: /tmp/hosts
34+
line: 127.0.0.1 instance.localdomain instance
35+
create: true
2936
roles:
3037
- role: osp.edpm.env_data
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
edpm_nodes_validation_validate_fqdn: true
2+
edpm_nodes_validation_validate_fqdn_hosts_file: /tmp/hosts

roles/edpm_nodes_validation/tasks/main.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,26 @@
6464
- edpm_nodes_validation_validate_controllers_icmp|bool
6565
- edpm_nodes_validation_ping_test_ips | length > 0
6666

67-
- name: Verify the configured FQDN vs /etc/hosts
67+
- name: Verify a FQDN is set block
68+
when:
69+
- edpm_nodes_validation_check_for_fqdn|bool
70+
block:
71+
- name: Run hostname -f
72+
ansible.builtin.command: hostname -f
73+
register: hostname
74+
changed_when: false
75+
76+
- name: Verify a FQDN is set
77+
ansible.builtin.assert:
78+
that: hostname.stdout.find(".") != -1
79+
fail_msg: "{{ hostname.stdout }} does not contain . and does not appear to be an FQDN."
80+
success_msg: "{{ hostname.stdout }} contains . and appears to be an FQDN."
81+
82+
- name: Verify the configured FQDN vs {{ edpm_nodes_validation_validate_fqdn_hosts_file }}
6883
ansible.builtin.shell: |
6984
HOSTNAME=$(hostname)
7085
SHORT_NAME=$(hostname -s)
71-
FQDN_FROM_HOSTS=$(awk '$1 !~ /#/ && $3 == "'${SHORT_NAME}'"{print $2}' /etc/hosts)
86+
FQDN_FROM_HOSTS=$(awk '$1 !~ /#/ && $3 == "'${SHORT_NAME}'"{print $2}' {{ edpm_nodes_validation_validate_fqdn_hosts_file }})
7287
if [[ $HOSTNAME != $FQDN_FROM_HOSTS ]]; then
7388
echo "FAILURE"
7489
echo -e "System hostname: ${HOSTNAME}\nEntry from /etc/hosts: ${FQDN_FROM_HOSTS}\n"

0 commit comments

Comments
 (0)