From 376c607f376f6102ad3d2d371226832fb759c386 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Fri, 2 Mar 2018 12:20:03 +0000 Subject: [PATCH] Workaround for Bifrost being unable to write to /etc/hosts Bifrost cannot modify /etc/hosts from within a container, so add a host entry during bootstrap. This was previously fixed by Ied378b4dd755788e75ad1814cecb5700732ba83e but the logic in bifrost was changed [1], making it out of sync with kolla-ansible, and triggering a write to /etc/hosts. This change applies the new logic in bifrost to kolla-ansible, ensuring that the file will not need to change in the container. Longer term we should look at ways to make bifrost less eager to modify /etc/hosts, accepting any file that will work for RabbitMQ. [1] https://github.com/openstack/bifrost/commit/60b9a9917e987e321b97b0f611fc2c77813be8b0 Change-Id: I0ee05feae3630435b2ec52cfeddf33647a974ee0 Closes-Bug: #1661009 --- ansible/roles/bifrost/tasks/config.yml | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/ansible/roles/bifrost/tasks/config.yml b/ansible/roles/bifrost/tasks/config.yml index 11a59a6d3c..dac9d25cbe 100644 --- a/ansible/roles/bifrost/tasks/config.yml +++ b/ansible/roles/bifrost/tasks/config.yml @@ -35,15 +35,16 @@ - { src: "id_rsa.pub", dest: "id_rsa.pub" } - { src: "ssh_config", dest: "ssh_config" } -# NOTE(mgoddard): The following two tasks were lifted from the Bifrost plays. -# Because Bifrost cannot modify /etc/hosts from within the container we must -# do it here. -- name: "RabbitMQ - Testing if hostname is defined in /etc/hosts" - command: grep -i "{{ ansible_hostname }}" /etc/hosts - ignore_errors: yes - register: test_grep_fix_hostname - -- name: "RabbitMQ - Fixing /etc/hosts" - command: sed -i 's/localhost/{{ ansible_hostname }} localhost/' /etc/hosts - when: test_grep_fix_hostname.rc != 0 - become: True +# NOTE(mgoddard): The following task was lifted from a Bifrost play +# (playbooks/roles/bifrost-ironic-install/tasks/bootstrap.yml). Because +# Bifrost cannot modify /etc/hosts from within the container we must do it +# here. +- name: "Ensure /etc/hosts has good defaults" + lineinfile: + dest: "/etc/hosts" + regexp: "{{ item.regexp }}.*({{ ansible_hostname }}|localhost).*" + line: "{{ item.contents }}" + with_items: + - { regexp: '^127\.0\.0\.1', contents: '127.0.0.1 {{ ansible_hostname }} {{ ansible_fqdn }} localhost' } + - { regexp: '^::1', contents: '::1 {{ ansible_hostname }} {{ ansible_fqdn }} localhost ipv6-localhost ipv6-loopback' } + become: true