Verify if hosts file already managed with OSA

With this patch we ensure that duplicated records are not
created with rabbitmq role if hosts file already contain
OSA managed block. Managing hosts still might be required for
role usage outside of the OSA so we workaround this usecase.

Change-Id: Ia20902f0ffe21ce563966fee4d233e5ec3afe3d9
Related-Bug: #1960587
This commit is contained in:
Dmitriy Rabotyagov 2022-02-12 00:22:33 +02:00
parent ae3c16ba00
commit c8ce051651
3 changed files with 34 additions and 17 deletions

View File

@ -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(

View File

@ -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.

View File

@ -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