Browse Source

Clear the previous inventory during provisioning

If there was a left-over inventory from a previous run that had nodes
which were subsequently removed, these would still show up in the
Ansible's in-memory inventory and Ansible would fail trying to connect
to them.

This is because Ansible automatically loads the `inventory/hosts` file
if it exists and even if we overwrite it later, every node and group
still remains in the memory.

By removing the inventory file and and calling the `refresh_inventory`
meta task, we make sure that any left-over values are removed.
Tomas Sedovic 7 years ago
parent
commit
8a204aaec7
1 changed files with 8 additions and 0 deletions
  1. 8 0
      roles/static_inventory/tasks/main.yml

+ 8 - 0
roles/static_inventory/tasks/main.yml

@@ -1,4 +1,12 @@
 ---
+- name: Remove any existing inventory
+  file:
+    path: "{{ inventory_path }}/hosts"
+    state: absent
+
+- name: Refresh the inventory
+  meta: refresh_inventory
+
 - name: Generate in-memory inventory
   include: openstack.yml