From 5b9cf44498941d691ab4f776324b0285656cca6d Mon Sep 17 00:00:00 2001 From: Vadim Kuznetsov Date: Wed, 14 Nov 2018 16:41:45 -0500 Subject: [PATCH] use ansible_hostname to construct canonical_hostname in /etc/hosts inventory_hostname is ansible alias of the host. It may be equal to hostname in most cases, but also can be short alias for convenience. ansible_hostname is discovered hostname, i.e. real hostname. It make more sense to use real hostname to construct fqdn and use inventory_hostname as an alias. Change-Id: If980f67da27035aa81b554ef59dedaf5a34357f4 --- templates/openstack-host-hostfile-setup.sh.j2 | 8 ++++---- tests/test.yml | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/templates/openstack-host-hostfile-setup.sh.j2 b/templates/openstack-host-hostfile-setup.sh.j2 index cfe15b2c..b3555b43 100644 --- a/templates/openstack-host-hostfile-setup.sh.j2 +++ b/templates/openstack-host-hostfile-setup.sh.j2 @@ -24,13 +24,13 @@ function host_update { DOMAINNAME=$5 if [[ "${ANSHOSTNAME}" != "${RFCHOSTNAME}" ]] && [[ "${RFCHOSTNAME}" != "${INVHOSTNAME}" ]]; then - insert_host_entry "${IPADDR} ${RFCHOSTNAME}.${DOMAINNAME} ${RFCHOSTNAME} ${INVHOSTNAME} ${ANSHOSTNAME}" "${IPADDR}" + insert_host_entry "${IPADDR} ${ANSHOSTNAME}.${DOMAINNAME} ${RFCHOSTNAME} ${INVHOSTNAME} ${ANSHOSTNAME}" "${IPADDR}" elif [[ "${ANSHOSTNAME}" != "${RFCHOSTNAME}" ]] && [[ "${RFCHOSTNAME}" == "${INVHOSTNAME}" ]]; then - insert_host_entry "${IPADDR} ${RFCHOSTNAME}.${DOMAINNAME} ${RFCHOSTNAME} ${ANSHOSTNAME}" "${IPADDR}" + insert_host_entry "${IPADDR} ${ANSHOSTNAME}.${DOMAINNAME} ${RFCHOSTNAME} ${ANSHOSTNAME}" "${IPADDR}" elif [[ "${ANSHOSTNAME}" == "${RFCHOSTNAME}" ]] && [[ "${RFCHOSTNAME}" == "${INVHOSTNAME}" ]]; then - insert_host_entry "${IPADDR} ${RFCHOSTNAME}.${DOMAINNAME} ${RFCHOSTNAME}" "${IPADDR}" + insert_host_entry "${IPADDR} ${ANSHOSTNAME}.${DOMAINNAME} ${RFCHOSTNAME}" "${IPADDR}" else - insert_host_entry "${IPADDR} ${RFCHOSTNAME}.${DOMAINNAME} ${RFCHOSTNAME} ${INVHOSTNAME}" "${IPADDR}" + insert_host_entry "${IPADDR} ${ANSHOSTNAME}.${DOMAINNAME} ${RFCHOSTNAME} ${INVHOSTNAME}" "${IPADDR}" fi } diff --git a/tests/test.yml b/tests/test.yml index a644603b..53bc38e5 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -89,11 +89,12 @@ - "'dm_multipath' in modules_content" - "'ebtables' in modules_content" - "'vm.swappiness' in sysctl_content" - - "'127.111.111.101 test1.openstack.local test1' in hosts_content" - - "'127.111.111.102 test2.openstack.local test2' in hosts_content" - - "'127.111.111.103 test3.openstack.local test3' in hosts_content" + - "'127.0.0.1 {{ ansible_hostname }}.openstack.local localhost {{ ansible_hostname }}' in hosts_content" + - "'127.0.1.1 {{ ansible_hostname }}.openstack.local localhost {{ ansible_hostname }}' in hosts_content" + - "'127.111.111.101 {{ ansible_hostname }}.openstack.local test1 {{ ansible_hostname }}' in hosts_content" + - "'127.111.111.102 {{ ansible_hostname }}.openstack.local test2 {{ ansible_hostname }}' in hosts_content" + - "'127.111.111.103 {{ ansible_hostname }}.openstack.local test3 {{ ansible_hostname }}' in hosts_content" - "'127.111.111.103 test3.additional' not in hosts_content" - - "'127.0.1.1 localhost.openstack.local localhost' in hosts_content" - "release_file.stat.exists" - "systat_file.stat.exists" - "'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' in environment_content"