Resolve custom hosts records on hosts
In order to save quite some time during the role execution, we apply run_once when defining /etc/hosts content. While this good for "static" content which is based on the inventory, resolving openstack_host_custom_hosts_records once may lead to unexpected behaviour. For instance, if host record depends on some specific group or other variables defined in host/group variables. In order to resolve it accordingly, we merge status and custom records together in blockinfile, which allows to resolve record individually for each host and not having penalty for most usecases. Change-Id: I48274de908fc6dc4a2e22a789e8355c7ba263599 (cherry picked from commit 88a9be604b4fde8bca921b0878cb1c3e4da36541)
This commit is contained in:
parent
6b0f7753c5
commit
11bcec95de
@ -17,7 +17,7 @@
|
||||
run_once: true
|
||||
set_fact:
|
||||
_etc_hosts_content: |-
|
||||
{% set records = openstack_host_custom_hosts_records %}
|
||||
{% set records = [] %}
|
||||
{% set _groups = groups['all'] %}
|
||||
{% set _ = _groups.remove('localhost') %}
|
||||
{% for item in _groups %}
|
||||
@ -42,7 +42,7 @@
|
||||
- name: Update hosts file
|
||||
blockinfile:
|
||||
dest: /etc/hosts
|
||||
block: "{{ _etc_hosts_content | join('\n') }}"
|
||||
block: "{{ (_etc_hosts_content + openstack_host_custom_hosts_records) | join('\n') }}"
|
||||
marker: "### {mark} OPENSTACK-ANSIBLE MANAGED BLOCK ###"
|
||||
when:
|
||||
- openstack_host_manage_hosts_file | bool
|
||||
@ -50,7 +50,7 @@
|
||||
- name: Update hosts file on deploy host
|
||||
blockinfile:
|
||||
dest: /etc/hosts
|
||||
block: "{{ _etc_hosts_content | join('\n') }}"
|
||||
block: "{{ (_etc_hosts_content + openstack_host_custom_hosts_records) | join('\n') }}"
|
||||
marker: "### {mark} OPENSTACK-ANSIBLE {{ lookup('env', 'OSA_CONFIG_DIR') }} MANAGED BLOCK ###"
|
||||
run_once: True
|
||||
delegate_to: localhost
|
||||
|
Loading…
x
Reference in New Issue
Block a user