From f4e74ea7143b96554023c604620cac0b5f5a5753 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Mon, 23 Apr 2018 15:13:01 +0100 Subject: [PATCH] Ensure facts are updated for new containers When the new containers are built, we currently only collect a minimal amount of facts afterwards. This patch ensures that a broader set of facts are updated to ensure that we have the updated distribution information, networking and storage facts. We do this for both types of containers to ensure consistency in the approach. Related-Bug: 1765438 Change-Id: I620e35d0942a6d4a55e05ae441d0e6ee2e4a67c4 --- playbooks/containers-lxc-create.yml | 14 +++++++++++--- playbooks/containers-nspawn-create.yml | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/playbooks/containers-lxc-create.yml b/playbooks/containers-lxc-create.yml index c9b0b5ca4a..8ebb152984 100644 --- a/playbooks/containers-lxc-create.yml +++ b/playbooks/containers-lxc-create.yml @@ -40,10 +40,18 @@ delay: "{{ lxc_container_wait_params.delay | default(omit) }}" sleep: "{{ lxc_container_wait_params.sleep | default(omit) }}" timeout: "{{ lxc_container_wait_params.timeout | default(omit) }}" - - name: Set local facts for new container(s) + + # When using gather_facts with smart gathering, + # the facts aren't fully updated unless they + # are old. Using the setup module in a task + # does a more thorough collection. + # Given we've just created the container, it is + # best that we do a full collection of facts - + # otherwise we end up with a stale set which + # has stuff like the hostname = localhost. + - name: Gather facts for new container(s) setup: - filter: ansible_local - gather_subset: "!all" + gather_subset: "network,hardware,virtual" environment: "{{ deployment_environment_variables | default({}) }}" tags: - lxc-containers-create diff --git a/playbooks/containers-nspawn-create.yml b/playbooks/containers-nspawn-create.yml index 0e263dc231..3162727e96 100644 --- a/playbooks/containers-nspawn-create.yml +++ b/playbooks/containers-nspawn-create.yml @@ -37,6 +37,25 @@ user: root roles: - role: "nspawn_container_create" + post_tasks: + - name: Wait for container connectivity + wait_for_connection: + connect_timeout: "{{ lxc_container_wait_params.connect_timeout | default(omit) }}" + delay: "{{ lxc_container_wait_params.delay | default(omit) }}" + sleep: "{{ lxc_container_wait_params.sleep | default(omit) }}" + timeout: "{{ lxc_container_wait_params.timeout | default(omit) }}" + + # When using gather_facts with smart gathering, + # the facts aren't fully updated unless they + # are old. Using the setup module in a task + # does a more thorough collection. + # Given we've just created the container, it is + # best that we do a full collection of facts - + # otherwise we end up with a stale set which + # has stuff like the hostname = localhost. + - name: Gather facts for new container(s) + setup: + gather_subset: "network,hardware,virtual" environment: "{{ deployment_environment_variables | default({}) }}" tags: - nspawn-containers-create