Merge "Remove /etc/hosts entries pointing hostname to localhost and prevent cloud-init to manage /etc/hosts"

This commit is contained in:
Zuul 2019-10-11 18:08:35 +00:00 committed by Gerrit Code Review
commit 9e18c8fc69

View File

@ -16,6 +16,18 @@
become: True
when: customize_etc_hosts | bool
# NOTE(mgoddard): Ubuntu includes a line in /etc/hosts that makes the local
# hostname and nodename (if different) point to 127.0.1.1. This can break
# RabbitMQ, which expects the hostname to resolve to the API network address.
# Remove these troublesome entries.
- name: Ensure hostname does not point to loopback in /etc/hosts
lineinfile:
dest: /etc/hosts
regexp: "^127.\\d+.\\d+.\\d+(\\s+{{ ansible_nodename }})?\\s+{{ ansible_hostname }}$"
state: absent
become: True
when: customize_etc_hosts | bool
- name: Generate /etc/hosts for all of the nodes
blockinfile:
dest: /etc/hosts
@ -35,6 +47,26 @@
- inventory_hostname not in groups['bifrost'] or
'ansible_' + hostvars[inventory_hostname]['api_interface'] in hostvars[inventory_hostname]
# NOTE(osmanlicilegi): The distribution might come with cloud-init installed, and manage_etc_hosts
# configuration enabled. If so, it will override the file /etc/hosts from cloud-init templates at
# every boot, which will break RabbitMQ. To prevent this happens, first we check whether cloud-init
# has been installed, and then set manage_etc_hosts to false.
- name: Check whether cloud-init has been installed, and ensure manage_etc_hosts is disabled
block:
- name: Ensure /etc/cloud/cloud.cfg exists
stat:
path: /etc/cloud/cloud.cfg
register: cloud_init
- name: Disable cloud-init manage_etc_hosts
copy:
content: "manage_etc_hosts: false"
dest: /etc/cloud/cloud.cfg.d/99-kolla.cfg
mode: "0660"
when: cloud_init.stat.exists
become: True
when: customize_etc_hosts | bool
- name: Ensure sudo group is present
group:
name: sudo