From 8e9bdba3226bc69250da9d59825e4950f2f211eb Mon Sep 17 00:00:00 2001 From: Jonathan Rosser Date: Wed, 17 Jun 2020 14:27:58 +0100 Subject: [PATCH] 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 --- playbooks/common-tasks/os-lxc-container-setup.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/playbooks/common-tasks/os-lxc-container-setup.yml b/playbooks/common-tasks/os-lxc-container-setup.yml index 53a4ba4cbd..84c4de34a6 100644 --- a/playbooks/common-tasks/os-lxc-container-setup.yml +++ b/playbooks/common-tasks/os-lxc-container-setup.yml @@ -133,6 +133,14 @@ tags: - 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 wait_for_connection: connect_timeout: "{{ lxc_container_wait_params.connect_timeout | default(omit) }}"