Preserve inode when updating /etc/hosts
Containers configured by tripleo bind-mount /etc/hosts directly,
which means any change to that file has to preserve the original
inode, otherwise the containers will get out of sync with the
host and will not see updates.
Change tripleo_host_entries to not depend on atomic semantics of
ansible, which changes inodes on update. Instead, perform a
non-atomic update to preserve inodes, and rely on the retry
logics of openstack containers to recover from unexpected
behaviour in case /etc/hosts is consumed while it is being updated.
Closes-Bug: #1882290
Change-Id: I34dd9121bbd650b79cb523e4dbed5949a0e7d52d
(cherry picked from commit 7761249774
)
This commit is contained in:
parent
5bfb5ec7f8
commit
c6b06129f8
|
@ -15,15 +15,36 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
|
||||||
|
- name: Create temporary file for hosts
|
||||||
|
become: true
|
||||||
|
tempfile:
|
||||||
|
state: file
|
||||||
|
suffix: tmphosts
|
||||||
|
register: tripleo_hosts_entries_tmp_hosts
|
||||||
|
check_mode: false
|
||||||
|
tags:
|
||||||
|
- tripleo_hosts_entries
|
||||||
|
|
||||||
|
- name: Prepare temporary /etc/hosts
|
||||||
|
become: true
|
||||||
|
copy:
|
||||||
|
remote_src: true
|
||||||
|
src: "{{ tripleo_hosts_entries_hosts_path }}"
|
||||||
|
dest: "{{ tripleo_hosts_entries_tmp_hosts.path }}"
|
||||||
|
mode: preserve
|
||||||
|
tags:
|
||||||
|
- tripleo_hosts_entries
|
||||||
|
|
||||||
- name: Remove old Heat hosts configuration (if present)
|
- name: Remove old Heat hosts configuration (if present)
|
||||||
become: true
|
become: true
|
||||||
blockinfile:
|
blockinfile:
|
||||||
state: absent
|
state: absent
|
||||||
path: "{{ tripleo_hosts_entries_hosts_path }}"
|
path: "{{ tripleo_hosts_entries_tmp_hosts.path }}"
|
||||||
block: ""
|
block: ""
|
||||||
marker: "# {mark}"
|
marker: "# {mark}"
|
||||||
marker_begin: "HEAT_HOSTS_START - Do not edit manually within this section!"
|
marker_begin: "HEAT_HOSTS_START - Do not edit manually within this section!"
|
||||||
marker_end: "HEAT_HOSTS_END"
|
marker_end: "HEAT_HOSTS_END"
|
||||||
|
register: tripleo_hosts_entries_heat_marker
|
||||||
tags:
|
tags:
|
||||||
- tripleo_hosts_entries
|
- tripleo_hosts_entries
|
||||||
|
|
||||||
|
@ -50,11 +71,11 @@
|
||||||
tags:
|
tags:
|
||||||
- tripleo_hosts_entries
|
- tripleo_hosts_entries
|
||||||
|
|
||||||
- name: Update /etc/hosts
|
- name: Prepare new /etc/hosts
|
||||||
become: true
|
become: true
|
||||||
blockinfile:
|
blockinfile:
|
||||||
create: true
|
create: true
|
||||||
path: "{{ tripleo_hosts_entries_hosts_path }}"
|
path: "{{ tripleo_hosts_entries_tmp_hosts.path }}"
|
||||||
# BOF denotes the beginning of the file.
|
# BOF denotes the beginning of the file.
|
||||||
insertbefore: BOF
|
insertbefore: BOF
|
||||||
block: |
|
block: |
|
||||||
|
@ -64,5 +85,22 @@
|
||||||
tripleo_hosts_entries_extra_hosts_entries | default([]) %}
|
tripleo_hosts_entries_extra_hosts_entries | default([]) %}
|
||||||
{{ host }}
|
{{ host }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
register: tripleo_hosts_entries_new_entries
|
||||||
|
tags:
|
||||||
|
- tripleo_hosts_entries
|
||||||
|
|
||||||
|
- name: Update /etc/hosts contents (if changed)
|
||||||
|
become: true
|
||||||
|
# cp preserves the inode of the existing file tripleo_hosts_entries_hosts_path
|
||||||
|
command: cp "{{ tripleo_hosts_entries_tmp_hosts.path }}" "{{ tripleo_hosts_entries_hosts_path }}"
|
||||||
|
when: tripleo_hosts_entries_heat_marker.changed or tripleo_hosts_entries_new_entries.changed
|
||||||
|
tags:
|
||||||
|
- tripleo_hosts_entries
|
||||||
|
|
||||||
|
- name: Clean up temporary hosts file
|
||||||
|
file:
|
||||||
|
path: "{{ tripleo_hosts_entries_tmp_hosts.path }}"
|
||||||
|
state: absent
|
||||||
|
when: tripleo_hosts_entries_tmp_hosts.path is defined
|
||||||
tags:
|
tags:
|
||||||
- tripleo_hosts_entries
|
- tripleo_hosts_entries
|
||||||
|
|
Loading…
Reference in New Issue