Wait for systemd-tmpfiles-setup service to complete after container restart

There is a race condition between starting an lxc container and executing
the first ansible task. Ansible makes heavy use of /tmp and the first
task executed after 'lxc-start' will collide with systemd-tmpfiles-setup
which by default removes all content from /tmp, including the working
files of any ansible task which happens to be running. This causes a fatal
error for ansible which cannot be recovered with retries.

This patch adds a raw command to check the state of the tmpfiles-setup
service and wait until it has completed, avoiding the race confdition.

Change-Id: I4ada8473bfd17b763bde16ac95099ddf7deb541c
This commit is contained in:
Jonathan Rosser 2020-06-17 14:27:58 +01:00
parent f543a71753
commit 8e9bdba322

View File

@ -133,6 +133,14 @@
tags: tags:
- common-lxc - common-lxc
- name: Wait for container tmpfiles-setup finish
raw: systemctl status systemd-tmpfiles-setup.service | grep Process | grep 'code=exited' >/dev/null
register: systemd_tmpfiles
until: systemd_tmpfiles.rc == 0
retries: 20
delay: 2
changed_when: false
- name: Wait for container connectivity - name: Wait for container connectivity
wait_for_connection: wait_for_connection:
connect_timeout: "{{ lxc_container_wait_params.connect_timeout | default(omit) }}" connect_timeout: "{{ lxc_container_wait_params.connect_timeout | default(omit) }}"