diff --git a/defaults/main.yml b/defaults/main.yml index 4a760875..fe5ab3d9 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -29,8 +29,10 @@ rabbitmq_node_address: "{{ ansible_host }}" rabbit_system_user_name: rabbitmq rabbit_system_group_name: rabbitmq -# Hosts file entries (set this to an empty list to disable /etc/hosts generation -# for the rabbitmq cluster nodes) +# Allow role to adjust /etc/hosts file +rabbitmq_manage_hosts_entries: True + +# Hosts file entries rabbitmq_hosts_entries: >- {{ groups[rabbitmq_host_group] | map('extract', hostvars) | list | json_query( diff --git a/releasenotes/notes/rabbitmq_manage_hosts-834150c45dfc0771.yaml b/releasenotes/notes/rabbitmq_manage_hosts-834150c45dfc0771.yaml new file mode 100644 index 00000000..707a0ce8 --- /dev/null +++ b/releasenotes/notes/rabbitmq_manage_hosts-834150c45dfc0771.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + Added variable ``rabbitmq_manage_hosts_entries`` that controls if + rabbitmq_server role will attempt to adjust /etc/hosts file +fixes: + - | + Do not duplicate records in /etc/hosts file by rabbitmq role when hosts + file is already managed by OSA. diff --git a/tasks/rabbitmq_pre_install.yml b/tasks/rabbitmq_pre_install.yml index 393dc6a2..22e40829 100644 --- a/tasks/rabbitmq_pre_install.yml +++ b/tasks/rabbitmq_pre_install.yml @@ -30,21 +30,27 @@ - rabbitmq-package-rpm - rabbitmq-package-rpm-get -- name: Fix /etc/hosts - lineinfile: - dest: /etc/hosts - state: present - line: "{{ item.address }} {{ item.hostnames | join(' ') }}" - with_items: "{{ rabbitmq_hosts_entries }}" - tags: - - rabbitmq-config - -- name: Ensure localhost /etc/hosts entry is correct - lineinfile: - dest: /etc/hosts - state: present - line: '127.0.0.1 localhost' - regexp: '^127.0.0.1' +- name: Manage /etc/hosts files + block: + - name: Fail if hosts file is not managed yet + command: grep "OPENSTACK-ANSIBLE MANAGED BLOCK" /etc/hosts + changed_when: false + rescue: + - name: Rescue failure and add required records + lineinfile: + dest: /etc/hosts + state: present + line: "{{ item.address }} {{ item.hostnames | join(' ') }}" + with_items: "{{ rabbitmq_hosts_entries }}" + always: + - name: Ensure localhost /etc/hosts entry is correct + lineinfile: + dest: /etc/hosts + state: present + line: '127.0.0.1 localhost' + regexp: '^127\.0\.0\.1' + when: + - rabbitmq_manage_hosts_entries | bool tags: - rabbitmq-config