group_vars: Refactor provisioner/bifrost

This change refactors bifrost provisioner playbooks and
roles to use group_vars instead of using vars from
engine/engine/var directory.

As bifrost/provision.sh is run on localhost initially,
it uses the newly created inventory file, localhost.ini,
to enable the use of group_vars. In the last command of
bifrost/provision.sh, bifrost_inventory.py is copied to
engine/engine/inventory to access to group_vars so the
the new full inventory file, inventory.ini, to use during
stack installation can be generated.

See the first change in series for the reasoning of
switching to group_vars which has additional information
as well.

Change-Id: I0cc76c2d2e1fb3b192e395c64f5df476b68a9200
diff --git a/playbooks/create-libvirt-resources.yml b/playbooks/create-libvirt-resources.yml
index 73638ad..07bc925 100644
--- a/playbooks/create-libvirt-resources.yml
+++ b/playbooks/create-libvirt-resources.yml
@@ -21,11 +21,6 @@
   connection: local
   become: yes
   gather_facts: true
-  vars_files:
-    - "{{ engine_path }}/engine/var/versions.yml"
-    - "{{ engine_path }}/engine/var/global.yml"
-    - "{{ pdf_file }}"
-    - "{{ idf_file }}"
 
   roles:
     - role: prepare-libvirt
diff --git a/playbooks/generate-inventory.yml b/playbooks/generate-inventory.yml
index 4fa7ffd..3bac81d 100644
--- a/playbooks/generate-inventory.yml
+++ b/playbooks/generate-inventory.yml
@@ -20,11 +20,6 @@
 - hosts: baremetal
   remote_user: root
   gather_facts: true
-  vars_files:
-    - "{{ engine_path }}/engine/var/versions.yml"
-    - "{{ engine_path }}/engine/var/global.yml"
-    - "{{ pdf_file }}"
-    - "{{ idf_file }}"
 
   roles:
     - role: get-baremetal-info
@@ -32,11 +27,6 @@
 - hosts: localhost
   connection: local
   gather_facts: true
-  vars_files:
-    - "{{ engine_path }}/engine/var/versions.yml"
-    - "{{ engine_path }}/engine/var/global.yml"
-    - "{{ pdf_file }}"
-    - "{{ idf_file }}"
 
   roles:
     - role: generate-inventory
diff --git a/playbooks/install-configure-bifrost.yml b/playbooks/install-configure-bifrost.yml
index 6cc80a4..3e6cd49 100644
--- a/playbooks/install-configure-bifrost.yml
+++ b/playbooks/install-configure-bifrost.yml
@@ -20,11 +20,6 @@
 - hosts: localhost
   connection: local
   gather_facts: true
-  vars_files:
-    - "{{ engine_path }}/engine/var/versions.yml"
-    - "{{ engine_path }}/engine/var/global.yml"
-    - "{{ pdf_file }}"
-    - "{{ idf_file }}"
 
   roles:
     - role: install-configure-bifrost
diff --git a/playbooks/roles/generate-inventory/tasks/generate-kolla-inventory.yml b/playbooks/roles/generate-inventory/tasks/generate-kolla-inventory.yml
index 05c96fc..697e3c7 100644
--- a/playbooks/roles/generate-inventory/tasks/generate-kolla-inventory.yml
+++ b/playbooks/roles/generate-inventory/tasks/generate-kolla-inventory.yml
@@ -17,9 +17,16 @@
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
 
+# TODO - group_vars: needed for backward compatibility - remove this once the transition is done
 - name: Generate Kolla inventory from PDF and IDF
   template:
     src:  "inventory_kolla_{{ openstack_version }}.ini.j2"
     dest: "{{ config_path }}/inventory.ini"
 
+# TODO - group_vars: update the task name once the transition is done
+- name: Generate Kolla inventory from PDF and IDF (new)
+  template:
+    src:  "inventory_kolla_{{ openstack_version }}.ini.j2"
+    dest: "{{ inventory_path }}/inventory.ini"
+
 # vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/generate-inventory/tasks/generate-kubespray-inventory.yml b/playbooks/roles/generate-inventory/tasks/generate-kubespray-inventory.yml
index 5738a87..becf73c 100644
--- a/playbooks/roles/generate-inventory/tasks/generate-kubespray-inventory.yml
+++ b/playbooks/roles/generate-inventory/tasks/generate-kubespray-inventory.yml
@@ -17,9 +17,16 @@
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
 
+# TODO - group_vars: needed for backward compatibility - remove this once the transition is done
 - name: Generate Kubespray inventory from PDF and IDF
   template:
     src:  inventory_kubespray.ini.j2
     dest: "{{ config_path }}/inventory.ini"
 
+# TODO - group_vars: update the task name once the transition is done
+- name: Generate Kubespray inventory from PDF and IDF (new)
+  template:
+    src:  inventory_kubespray.ini.j2
+    dest: "{{ inventory_path }}/inventory.ini"
+
 # vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/generate-inventory/tasks/main.yml b/playbooks/roles/generate-inventory/tasks/main.yml
index 75a5efe..122b1ec 100644
--- a/playbooks/roles/generate-inventory/tasks/main.yml
+++ b/playbooks/roles/generate-inventory/tasks/main.yml
@@ -25,3 +25,10 @@
 - include: generate-kolla-inventory.yml
   when: installer_type == 'kolla'
 
+# we are done with bifrost_inventory.py so we can remove it
+- name: Delete bifrost_inventory.py
+  file:
+    path: "{{ inventory_path }}/bifrost_inventory.py"
+    state: absent
+
+# vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/get-baremetal-info/tasks/main.yml b/playbooks/roles/get-baremetal-info/tasks/main.yml
index aca6313..7301ba3 100644
--- a/playbooks/roles/get-baremetal-info/tasks/main.yml
+++ b/playbooks/roles/get-baremetal-info/tasks/main.yml
@@ -54,3 +54,5 @@
   when:
     - interface.macaddress == node.interfaces[idf.net_config.neutron.interface].mac_address
     - "'.' not in interface.device"
+
+# vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/install-configure-bifrost/tasks/create-bifrost-inventory-entry.yml b/playbooks/roles/install-configure-bifrost/tasks/create-bifrost-inventory-entry.yml
index eb906d1..35ed13d 100644
--- a/playbooks/roles/install-configure-bifrost/tasks/create-bifrost-inventory-entry.yml
+++ b/playbooks/roles/install-configure-bifrost/tasks/create-bifrost-inventory-entry.yml
@@ -16,6 +16,7 @@
 #
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
+
 - name: Find node in PDF by node name '{{ host.key }}'
   set_fact:
     hostname: "{{ host.value }}"
@@ -49,3 +50,5 @@
 - name: Add node data of '{{ hostname }}' to bifrost inventory
   set_fact:
     bifrost_inventory: "{{ bifrost_inventory | combine({hostname: node_data}) }}"
+
+# vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/install-configure-bifrost/tasks/create-bifrost-inventory-file.yml b/playbooks/roles/install-configure-bifrost/tasks/create-bifrost-inventory-file.yml
index 95d8016..fff4302 100644
--- a/playbooks/roles/install-configure-bifrost/tasks/create-bifrost-inventory-file.yml
+++ b/playbooks/roles/install-configure-bifrost/tasks/create-bifrost-inventory-file.yml
@@ -16,6 +16,7 @@
 #
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
+
 - name: Remove previous bifrost inventory {{ bifrost_inventory_source }}
   file:
     state: absent
diff --git a/playbooks/roles/install-configure-bifrost/tasks/create-bifrost-playbooks.yml b/playbooks/roles/install-configure-bifrost/tasks/create-bifrost-playbooks.yml
index 21e6e94..8ecfea5 100644
--- a/playbooks/roles/install-configure-bifrost/tasks/create-bifrost-playbooks.yml
+++ b/playbooks/roles/install-configure-bifrost/tasks/create-bifrost-playbooks.yml
@@ -16,6 +16,7 @@
 #
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
+
 - name: Load distribution variables
   include_vars:
     file: "{{ distro }}.yml"
diff --git a/playbooks/roles/install-configure-bifrost/tasks/download-image.yml b/playbooks/roles/install-configure-bifrost/tasks/download-image.yml
index c42f4e2..95f8729 100644
--- a/playbooks/roles/install-configure-bifrost/tasks/download-image.yml
+++ b/playbooks/roles/install-configure-bifrost/tasks/download-image.yml
@@ -16,6 +16,7 @@
 #
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
+
 - name: Set download source and destination for the deployment image
   set_fact:
     source: "{{ item.source }}"
@@ -42,3 +43,5 @@
       sha256sum: "{{ header.x_checksum_sha256 }}"
   when: download_image
   become: yes
+
+# vim: set ts=2 sw=2 expandtab:
diff --git a/playbooks/roles/install-configure-bifrost/tasks/main.yml b/playbooks/roles/install-configure-bifrost/tasks/main.yml
index 1befc88..8379e6b 100644
--- a/playbooks/roles/install-configure-bifrost/tasks/main.yml
+++ b/playbooks/roles/install-configure-bifrost/tasks/main.yml
@@ -16,6 +16,7 @@
 #
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
+
 - include_tasks: cleanup-bifrost.yml
 
 - name: Clone bifrost repository and checkout '{{ bifrost_version }}'
diff --git a/playbooks/roles/prepare-libvirt/tasks/main.yml b/playbooks/roles/prepare-libvirt/tasks/main.yml
index 4978b44..8edba81 100644
--- a/playbooks/roles/prepare-libvirt/tasks/main.yml
+++ b/playbooks/roles/prepare-libvirt/tasks/main.yml
@@ -16,6 +16,7 @@
 #
 # SPDX-License-Identifier: Apache-2.0
 # ============LICENSE_END=========================================================
+
 - name: "Load distribution defaults"
   include_vars: "{{ ansible_os_family | lower }}.yml"
 
diff --git a/provision.sh b/provision.sh
index d64b659..e45a25d 100755
--- a/provision.sh
+++ b/provision.sh
@@ -28,15 +28,16 @@
 # TODO: ignoring SC2015 for the timebeing so we don't break things
 # shellcheck disable=SC2015
 # set the BAREMETAL variable
-grep -o "vendor.*" "${ENGINE_CACHE}/config/pdf.yml" | grep -q libvirt && export BAREMETAL=false || export BAREMETAL=true
+grep -o "vendor.*" "${ENGINE_PATH}/engine/inventory/group_vars/all/pdf.yaml" | grep -q libvirt && export BAREMETAL=false || export BAREMETAL=true
 
 # create libvirt resources if not baremetal, install and configure bifrost
 echo "Info: Prepare nodes, configure bifrost and create bifrost inventory"
 echo "-------------------------------------------------------------------------"
 cd "${ENGINE_PATH}"
 ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \
-  -e baremetal="${BAREMETAL}" \
-  "${PROVISIONER_ROOT_DIR}/playbooks/main.yml"
+    -i "${ENGINE_PATH}/engine/inventory/localhost.ini" \
+    -e baremetal="${BAREMETAL}" \
+    "${PROVISIONER_ROOT_DIR}/playbooks/main.yml"
 echo "-------------------------------------------------------------------------"
 
 # Bifrost looks at environment variable VENV to see if it needs to use
@@ -53,27 +54,31 @@
 echo "-------------------------------------------------------------------------"
 cd "${ENGINE_CACHE}/repos/bifrost/playbooks"
 ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \
-  -i inventory/target \
-  -e ansible_python_interpreter="${ENGINE_VENV}/bin/python" \
-  bifrost-install.yml
+    -i inventory/target \
+    -e ansible_python_interpreter="${ENGINE_VENV}/bin/python" \
+    bifrost-install.yml
 echo "-------------------------------------------------------------------------"
 
 echo "Info: Enroll and deploy nodes using bifrost"
 echo "-------------------------------------------------------------------------"
 cd "${ENGINE_CACHE}/repos/bifrost/playbooks"
 ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \
-  -i inventory/bifrost_inventory.py \
-  -e ansible_python_interpreter="${ENGINE_VENV}/bin/python" \
-  bifrost-enroll-deploy.yml
+    -i inventory/bifrost_inventory.py \
+    -e ansible_python_interpreter="${ENGINE_VENV}/bin/python" \
+    bifrost-enroll-deploy.yml
 echo "-------------------------------------------------------------------------"
 
+# copy bifrost_inventory.py to engine inventory folder so we can access to group_vars
+/bin/cp -f "${ENGINE_CACHE}/repos/bifrost/playbooks/inventory/bifrost_inventory.py" \
+    "${ENGINE_PATH}/engine/inventory/bifrost_inventory.py"
+
 echo "Info: Generate Ansible inventory"
 echo "-------------------------------------------------------------------------"
-cd "${ENGINE_CACHE}/repos/bifrost/playbooks"
+cd "${ENGINE_PATH}"
 ansible-playbook "${ENGINE_ANSIBLE_PARAMS[@]}" \
-  -i inventory/bifrost_inventory.py \
-  --ssh-extra-args " -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" \
-  "${PROVISIONER_ROOT_DIR}/playbooks/generate-inventory.yml"
+    -i "${ENGINE_PATH}/engine/inventory/bifrost_inventory.py" \
+    --ssh-extra-args " -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" \
+    "${PROVISIONER_ROOT_DIR}/playbooks/generate-inventory.yml"
 
 echo "-------------------------------------------------------------------------"
 echo "Info: Nodes are provisioned using bifrost!"