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_user_name: rabbitmq
rabbit_system_group_name: rabbitmq rabbit_system_group_name: rabbitmq
# Hosts file entries (set this to an empty list to disable /etc/hosts generation # Allow role to adjust /etc/hosts file
# for the rabbitmq cluster nodes) rabbitmq_manage_hosts_entries: True
# Hosts file entries
rabbitmq_hosts_entries: >- rabbitmq_hosts_entries: >-
{{ groups[rabbitmq_host_group] | map('extract', hostvars) | list | {{ groups[rabbitmq_host_group] | map('extract', hostvars) | list |
json_query( 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
- rabbitmq-package-rpm-get - rabbitmq-package-rpm-get
- name: Fix /etc/hosts - name: Manage /etc/hosts files
lineinfile: block:
dest: /etc/hosts - name: Fail if hosts file is not managed yet
state: present command: grep "OPENSTACK-ANSIBLE MANAGED BLOCK" /etc/hosts
line: "{{ item.address }} {{ item.hostnames | join(' ') }}" changed_when: false
with_items: "{{ rabbitmq_hosts_entries }}" rescue:
tags: - name: Rescue failure and add required records
- rabbitmq-config lineinfile:
dest: /etc/hosts
- name: Ensure localhost /etc/hosts entry is correct state: present
lineinfile: line: "{{ item.address }} {{ item.hostnames | join(' ') }}"
dest: /etc/hosts with_items: "{{ rabbitmq_hosts_entries }}"
state: present always:
line: '127.0.0.1 localhost' - name: Ensure localhost /etc/hosts entry is correct
regexp: '^127.0.0.1' lineinfile:
dest: /etc/hosts
state: present
line: '127.0.0.1 localhost'
regexp: '^127\.0\.0\.1'
when:
- rabbitmq_manage_hosts_entries | bool
tags: tags:
- rabbitmq-config - rabbitmq-config