From 7434bed989ce03c25b83b66cb1f3b9678dd9c221 Mon Sep 17 00:00:00 2001 From: Andrew Bonney Date: Wed, 3 Feb 2021 09:11:07 +0000 Subject: [PATCH] Add hostname resolution to deploy host This addresses an issue with delegation to containers noticed as a result of https://github.com/ansible/ansible/issues/72776 which causes the container host to be accessed by its hostname. Where a separate deploy host is used, up to now this has not had its hosts file modified. This patch applies the same /etc/hosts entries to the deploy host which are used elsewhere. Change-Id: I82b48ba5cfe6e533426e7098c455b729084b2d51 --- defaults/main.yml | 6 ++++-- .../notes/deploy-hosts-file-657a385568f3df9c.yaml | 13 +++++++++++++ tasks/main.yml | 4 ++-- tasks/openstack_update_hosts_file.yml | 13 +++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/deploy-hosts-file-657a385568f3df9c.yaml diff --git a/defaults/main.yml b/defaults/main.yml index b986b1e3..311f65d8 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -34,10 +34,12 @@ openstack_host_sysstat_statistics_hour: 23 # Options are 'present' and 'latest' openstack_hosts_package_state: "latest" -## Enable/disable /etc/hosts file management +## Enable/disable /etc/hosts file management on OSA managed hosts ## You should make other arrangements for name resolution -## of OSA containers and hosts if disabling this +## of OSA containers and hosts if disabling these openstack_host_manage_hosts_file: true +## Enable/disable /etc/hosts file management on OSA deploy host +openstack_host_manage_deploy_hosts_file: true ## kernel modules for specific group hosts openstack_host_specific_kernel_modules: [] diff --git a/releasenotes/notes/deploy-hosts-file-657a385568f3df9c.yaml b/releasenotes/notes/deploy-hosts-file-657a385568f3df9c.yaml new file mode 100644 index 00000000..78c826e4 --- /dev/null +++ b/releasenotes/notes/deploy-hosts-file-657a385568f3df9c.yaml @@ -0,0 +1,13 @@ +--- +features: + - | + In deployments where a separate host is used to manage the OpenStack + Ansible configuration, the '/etc/hosts' file on that host will now include + a section adding hostname to IP resolution for all hosts in the inventory. + This can be enabled/disabled via 'openstack_host_manage_deploy_hosts_file'. +issues: + - | + Where a single OSA deploy host is used to manage multiple deployments, some + delegated Ansible tasks are performed using hostnames rather than IP + addresses due to Ansible issue 72776. Hostnames such as 'infra1' will be + ambiguous, so use of separate hosts for each deployment is recommended. diff --git a/tasks/main.yml b/tasks/main.yml index 8c955763..c846a543 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -50,10 +50,10 @@ # Configure host files should apply to all nodes - name: Configure etc hosts files import_tasks: openstack_update_hosts_file.yml - when: - - openstack_host_manage_hosts_file | bool tags: - openstack_hosts-config + when: + - (openstack_host_manage_hosts_file | bool) or (openstack_host_manage_deploy_hosts_file | bool) - name: Remove the blacklisted packages package: diff --git a/tasks/openstack_update_hosts_file.yml b/tasks/openstack_update_hosts_file.yml index b562572c..5e216f91 100644 --- a/tasks/openstack_update_hosts_file.yml +++ b/tasks/openstack_update_hosts_file.yml @@ -42,3 +42,16 @@ dest: /etc/hosts block: "{{ _etc_hosts_content | join('\n') }}" marker: "### {mark} OPENSTACK-ANSIBLE MANAGED BLOCK ###" + when: + - openstack_host_manage_hosts_file | bool + +- name: Update hosts file on deploy host + blockinfile: + dest: /etc/hosts + block: "{{ _etc_hosts_content | join('\n') }}" + marker: "### {mark} OPENSTACK-ANSIBLE {{ lookup('env', 'OSA_CONFIG_DIR') }} MANAGED BLOCK ###" + run_once: True + delegate_to: localhost + become: True + when: + - openstack_host_manage_deploy_hosts_file | bool