From 3d4ac3786772ec23791183b4c54a9d6fd922752e Mon Sep 17 00:00:00 2001
From: Manuel Buil <mbuil@suse.com>
Date: Fri, 4 May 2018 23:11:35 +0200
Subject: [PATCH] Use PDF to set up the XCI VMs

This patch is doing the first work item of the spec:

https://github.com/opnfv/releng-xci/blob/master/docs/specs/infra_manager.rst

It creates the required VMs by XCI to afterwards deploy the VIM. It does that
by reading the pdf provided by the user.

- It is currently assumed that the OS for the VM will be installed in the first
disk of the node described by the pdf

- It is assumed that the opnfv VM characteristics are not described in the pdf
but in a similar document called opnfv_vm.yml

- All references to csv from bifrost-create-vm-nodes were removed

Change-Id: I46a85284e4ce7df21cbf66f66619b35f74251e68
Signed-off-by: Manuel Buil <mbuil@suse.com>
Co-Authored-by: Markos Chandras <mchandras@suse.de>
---
 xci/config/aio-vars                                |   4 +-
 xci/config/ha-vars                                 |   6 +-
 xci/config/mini-vars                               |   6 +-
 xci/config/noha-vars                               |   6 +-
 xci/config/pinned-versions                         |   2 +-
 xci/files/xci-destroy-env.sh                       |   2 +-
 xci/infra/bifrost/infra-provision.sh               |  68 +++++++-
 .../{opnfv-virtual.yaml => opnfv-virtual.yml}      |  69 ++++++--
 ...ootstrap-bifrost.yml => xci-create-virtual.yml} |  32 +++-
 .../bifrost/playbooks/xci-prepare-virtual.yml      |  93 +++++++++++
 xci/infra/bifrost/scripts/bifrost-env.sh           |  33 ++++
 xci/infra/bifrost/scripts/bifrost-provision.sh     | 176 ---------------------
 xci/infra/bifrost/vars/debian.yml                  |  19 +++
 xci/infra/bifrost/vars/redhat.yml                  |  19 +++
 xci/infra/bifrost/vars/suse.yml                    |  19 +++
 .../roles/create-vm-nodes/defaults/main.yml        |   2 +-
 16 files changed, 341 insertions(+), 215 deletions(-)
 rename xci/infra/bifrost/playbooks/{opnfv-virtual.yaml => opnfv-virtual.yml} (72%)
 rename xci/infra/bifrost/playbooks/{bootstrap-bifrost.yml => xci-create-virtual.yml} (60%)
 create mode 100644 xci/infra/bifrost/playbooks/xci-prepare-virtual.yml
 create mode 100755 xci/infra/bifrost/scripts/bifrost-env.sh
 delete mode 100755 xci/infra/bifrost/scripts/bifrost-provision.sh
 create mode 100644 xci/infra/bifrost/vars/debian.yml
 create mode 100644 xci/infra/bifrost/vars/redhat.yml
 create mode 100644 xci/infra/bifrost/vars/suse.yml

diff --git a/xci/config/aio-vars b/xci/config/aio-vars
index 1d2e4f96..cff181a9 100755
--- a/xci/config/aio-vars
+++ b/xci/config/aio-vars
@@ -9,8 +9,8 @@
 #-------------------------------------------------------------------------------
 # Configure VM Nodes
 #-------------------------------------------------------------------------------
-export TEST_VM_NUM_NODES=1
-export TEST_VM_NODE_NAMES=opnfv
+export NUM_NODES=1
+export NODE_NAMES=opnfv
 export VM_DOMAIN_TYPE=${VM_DOMAIN_TYPE:-kvm}
 export VM_CPU=${VM_CPU:-8}
 export VM_DISK=${VM_DISK:-80}
diff --git a/xci/config/ha-vars b/xci/config/ha-vars
index 131de2a7..3440a855 100755
--- a/xci/config/ha-vars
+++ b/xci/config/ha-vars
@@ -9,9 +9,9 @@
 #-------------------------------------------------------------------------------
 # Configure VM Nodes
 #-------------------------------------------------------------------------------
-export TEST_VM_NUM_NODES=6
-[[ "$INSTALLER_TYPE" == "osa" ]] && export TEST_VM_NODE_NAMES="opnfv controller00 controller01 controller02 compute00 compute01"
-[[ "$INSTALLER_TYPE" == "kubespray" ]] && export TEST_VM_NODE_NAMES="opnfv master1 master2 master3 node1 node2"
+export NUM_NODES=6
+[[ "$INSTALLER_TYPE" == "osa" ]] && export NODE_NAMES="opnfv controller00 controller01 controller02 compute00 compute01"
+[[ "$INSTALLER_TYPE" == "kubespray" ]] && export NODE_NAMES="opnfv master1 master2 master3 node1 node2"
 export VM_DOMAIN_TYPE=${VM_DOMAIN_TYPE:-kvm}
 export VM_CPU=${VM_CPU:-6}
 export VM_DISK=${VM_DISK:-80}
diff --git a/xci/config/mini-vars b/xci/config/mini-vars
index 7d2b227b..9e7e6180 100755
--- a/xci/config/mini-vars
+++ b/xci/config/mini-vars
@@ -9,9 +9,9 @@
 #-------------------------------------------------------------------------------
 # Configure VM Nodes
 #-------------------------------------------------------------------------------
-export TEST_VM_NUM_NODES=3
-[[ "$INSTALLER_TYPE" == "osa" ]] && export TEST_VM_NODE_NAMES="opnfv controller00 compute00"
-[[ "$INSTALLER_TYPE" == "kubespray" ]] && export TEST_VM_NODE_NAMES="opnfv master1 node1"
+export NUM_NODES=3
+[[ "$INSTALLER_TYPE" == "osa" ]] && export NODE_NAMES="opnfv controller00 compute00"
+[[ "$INSTALLER_TYPE" == "kubespray" ]] && export NODE_NAMES="opnfv master1 node1"
 export VM_DOMAIN_TYPE=${VM_DOMAIN_TYPE:-kvm}
 export VM_CPU=${VM_CPU:-6}
 export VM_DISK=${VM_DISK:-80}
diff --git a/xci/config/noha-vars b/xci/config/noha-vars
index 8d30a243..2f3db993 100755
--- a/xci/config/noha-vars
+++ b/xci/config/noha-vars
@@ -9,9 +9,9 @@
 #-------------------------------------------------------------------------------
 # Configure VM Nodes
 #-------------------------------------------------------------------------------
-export TEST_VM_NUM_NODES=4
-[[ "$INSTALLER_TYPE" == "osa" ]] && export TEST_VM_NODE_NAMES="opnfv controller00 compute00 compute01"
-[[ "$INSTALLER_TYPE" == "kubespray" ]] && export TEST_VM_NODE_NAMES="opnfv master1 node1 node2"
+export NUM_NODES=4
+[[ "$INSTALLER_TYPE" == "osa" ]] && export NODE_NAMES="opnfv controller00 compute00 compute01"
+[[ "$INSTALLER_TYPE" == "kubespray" ]] && export NODE_NAMES="opnfv master1 node1 node2"
 export VM_DOMAIN_TYPE=${VM_DOMAIN_TYPE:-kvm}
 export VM_CPU=${VM_CPU:-6}
 export VM_DISK=${VM_DISK:-80}
diff --git a/xci/config/pinned-versions b/xci/config/pinned-versions
index da82c9cd..5ef0c7c2 100755
--- a/xci/config/pinned-versions
+++ b/xci/config/pinned-versions
@@ -28,7 +28,7 @@ export OPNFV_RELENG_VERSION="master"
 # use functest-healthcheck image that is known to work and contains the original list of testcases
 export OPNFV_FUNCTEST_HEALTHCHECK_DOCKER_IMAGE_DIGEST="sha256:faa1ec5778ac1580cc46f0e4f5abec24026868b95fc6fc3ae6023275dc980c2d"
 # HEAD of bifrost "master" as of 13.02.2018
-export OPENSTACK_BIFROST_VERSION=${OPENSTACK_BIFROST_VERSION:-"28b6b8c96f89532bbddeca513285e6c00db89205"}
+export OPENSTACK_BIFROST_VERSION=${OPENSTACK_BIFROST_VERSION:-"81e48e7b488c15516503b2b08f087f4a7ae9a673"}
 # HEAD of ironic "master" as of 13.02.2018
 export BIFROST_IRONIC_VERSION=${BIFROST_IRONIC_VERSION:-"9b8440aa318e4883a74ef8640ad5409dd22858a9"}
 # HEAD of ironic-client "master" as of 13.02.2018
diff --git a/xci/files/xci-destroy-env.sh b/xci/files/xci-destroy-env.sh
index 3de21795..c95ea838 100755
--- a/xci/files/xci-destroy-env.sh
+++ b/xci/files/xci-destroy-env.sh
@@ -40,7 +40,7 @@ fi
 # Destroy all XCI VMs on all flavors
 for varfile in ${flavors[@]}; do
     source ${XCI_PATH}/xci/config/${varfile}-vars
-    for vm in ${TEST_VM_NODE_NAMES}; do
+    for vm in ${NODE_NAMES}; do
         if which virsh &>/dev/null; then
             virsh destroy $vm &>/dev/null || true
             virsh undefine $vm &>/dev/null || true
diff --git a/xci/infra/bifrost/infra-provision.sh b/xci/infra/bifrost/infra-provision.sh
index 9c3adfc2..17eb4158 100644
--- a/xci/infra/bifrost/infra-provision.sh
+++ b/xci/infra/bifrost/infra-provision.sh
@@ -1,3 +1,11 @@
+# SPDX-license-identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2018 SUSE LINUX GmbH.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
 #-------------------------------------------------------------------------------
 # Start provisioning VM nodes
 #-------------------------------------------------------------------------------
@@ -8,14 +16,64 @@
 # - destroys VMs, removes ironic db, leases, logs
 # - creates and provisions VMs for the chosen flavor
 #-------------------------------------------------------------------------------
+
 BIFROST_ROOT_DIR="$(dirname $(realpath ${BASH_SOURCE[0]}))"
+export ANSIBLE_ROLES_PATH="$HOME/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:${XCI_PATH}/xci/playbooks/roles:${XCI_CACHE}/repos/bifrost/playbooks/roles"
+export ANSIBLE_LIBRARY="$HOME/.ansible/plugins/modules:/usr/share/ansible/plugins/modules:${XCI_CACHE}/repos/bifrost/playbooks/library"
 
-echo "Info: Starting provisining VM nodes using openstack/bifrost"
+echo "Info: Create XCI VM resources"
 echo "-------------------------------------------------------------------------"
-cd $BIFROST_ROOT_DIR/playbooks/
-ansible-playbook ${XCI_ANSIBLE_PARAMS} -i "localhost," bootstrap-bifrost.yml
-cd ${XCI_CACHE}/repos/bifrost
-bash ./scripts/bifrost-provision.sh
+
+ansible-playbook ${XCI_ANSIBLE_PARAMS} \
+        -i ${XCI_PATH}/xci/playbooks/dynamic_inventory.py \
+        -e num_nodes=${NUM_NODES} \
+        -e vm_domain_type=${VM_DOMAIN_TYPE} \
+        -e baremetal_json_file=/tmp/baremetal.json \
+        -e xci_distro=${XCI_DISTRO} \
+        ${BIFROST_ROOT_DIR}/playbooks/xci-create-virtual.yml
+
+
+ansible-playbook ${XCI_ANSIBLE_PARAMS} \
+        --private-key=${XCI_PATH}/xci/scripts/vm/id_rsa_for_dib \
+        --user=devuser \
+        -i ${XCI_PATH}/xci/playbooks/dynamic_inventory.py \
+        ${BIFROST_ROOT_DIR}/playbooks/xci-prepare-virtual.yml
+
+source ${XCI_CACHE}/repos/bifrost/scripts/bifrost-env.sh
+
+# This is hardcoded to delegate to localhost but we really need to delegate to opnfv instead.
+sed -i "/delegate_to:/d" ${XCI_CACHE}/repos/bifrost/playbooks/roles/bifrost-deploy-nodes-dynamic/tasks/main.yml
+
+ansible-playbook ${XCI_ANSIBLE_PARAMS} \
+    --user=devuser \
+    -i ${XCI_PATH}/xci/playbooks/dynamic_inventory.py \
+    -i ${XCI_CACHE}/repos/bifrost/playbooks/inventory/bifrost_inventory.py \
+    -e use_cirros=false \
+    -e testing_user=root \
+    -e test_vm_num_nodes=${NUM_NODES} \
+    -e test_vm_cpu='host-model' \
+    -e inventory_dhcp=false \
+    -e inventory_dhcp_static_ip=false \
+    -e enable_inspector=true \
+    -e inspect_nodes=true \
+    -e download_ipa=true \
+    -e create_ipa_image=false \
+    -e write_interfaces_file=true \
+    -e ipv4_gateway=192.168.122.1 \
+    -e wait_timeout=3600 \
+    -e enable_keystone=false \
+    -e ironicinspector_source_install=true \
+    -e ironicinspector_git_branch=${BIFROST_IRONIC_INSPECTOR_VERSION:-master} \
+    -e ironicinspectorclient_source_install=true \
+    -e ironicinspectorclient_git_branch=${BIFROST_IRONIC_INSPECTOR_CLIENT_VERSION:-master} \
+    -e ironicclient_source_install=true \
+    -e ironicclient_git_branch=${BIFROST_IRONIC_CLIENT_VERSION:-master} \
+    -e ironic_git_branch=${BIFROST_IRONIC_VERSION:-master} \
+    -e use_prebuilt_images=${BIFROST_USE_PREBUILT_IMAGES:-false} \
+    -e xci_distro=${XCI_DISTRO} \
+    -e ironic_url="http://192.168.122.2:6385/" \
+    ${BIFROST_ROOT_DIR}/playbooks/opnfv-virtual.yml
+
 echo "-----------------------------------------------------------------------"
 echo "Info: VM nodes are provisioned!"
 echo "-----------------------------------------------------------------------"
diff --git a/xci/infra/bifrost/playbooks/opnfv-virtual.yaml b/xci/infra/bifrost/playbooks/opnfv-virtual.yml
similarity index 72%
rename from xci/infra/bifrost/playbooks/opnfv-virtual.yaml
rename to xci/infra/bifrost/playbooks/opnfv-virtual.yml
index bb0daff6..68d76cfc 100644
--- a/xci/infra/bifrost/playbooks/opnfv-virtual.yaml
+++ b/xci/infra/bifrost/playbooks/opnfv-virtual.yml
@@ -7,11 +7,12 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 ---
-- hosts: localhost
-  connection: local
+- hosts: opnfv
   name: "Host and Ironic bootstrapping"
   become: yes
   gather_facts: yes
+  vars_files:
+    - "../vars/{{ ansible_os_family | lower }}.yml"
   pre_tasks:
     - name: Remove pre-existing leases file
       file: path=/var/lib/misc/dnsmasq.leases state=absent
@@ -52,6 +53,19 @@
             owner: 'root'
             group: 'root'
       when: use_prebuilt_images | bool == true
+    - name: Ensure /etc/hosts has good defaults
+      lineinfile:
+        create: yes
+        dest: "/etc/hosts"
+        regexp: "{{ item.regexp }}.*({{ ansible_hostname }}|localhost).*"
+        line: "{{ item.contents }}"
+      with_items:
+        - { regexp: '^127\.0\.0\.1', contents: '127.0.0.1 {{ ansible_hostname }} {{ ansible_fqdn }} localhost' }
+        - { regexp: '^::1', contents: '::1 {{ ansible_hostname }} {{ ansible_fqdn }} localhost ipv6-localhost ipv6-loopback' }
+    - name: Install required packages
+      package:
+        name: "{{ bifrost_required_devel_packages }}"
+        state: present
 
   roles:
     - role: bifrost-prep-for-install
@@ -59,7 +73,9 @@
     - role: bifrost-keystone-install
     - role: bifrost-ironic-install
       cleaning: false
-      testing: true
+      testing: false
+      enabled_hardware_types: ipmi
+      network_interface: "{{ ansible_default_ipv4.interface }}"
     # NOTE(TheJulia): While the next step creates a ramdisk, some elements
     # do not support ramdisk-image-create as they invoke steps to cleanup
     # the ramdisk which causes ramdisk-image-create to believe it failed.
@@ -89,7 +105,6 @@
         - transform_boot_image | bool == false
         - use_prebuilt_images | bool == false
     - role: bifrost-keystone-client-config
-      user: "{{ ansible_env.SUDO_USER }}"
       clouds:
         bifrost:
           config_username: "{{ ironic.keystone.default_username }}"
@@ -107,18 +122,36 @@
   vars:
     multinode_testing: "{{ inventory_dhcp | bool == true }}"
   become: no
-  connection: local
-  gather_facts: yes
-  pre_tasks:
+  gather_facts: False
+  tasks:
+    - name: Gathering facts
+      setup:
+      delegate_to: opnfv
+      delegate_facts: False
     - name: "Override default bifrost DNS if we are behind a proxy"
       set_fact:
          ipv4_nameserver: "192.168.122.1"
       when: lookup('env','http_proxy') != ''
-  roles:
-    - role: ironic-enroll-dynamic
-    - { role: ironic-inspect-node, when: inspect_nodes | default('false') | bool == true }
-    - role: bifrost-configdrives-dynamic
-    - role: bifrost-deploy-nodes-dynamic
+    - name: Find network interface in the OPNFV node
+      set_fact:
+        network_interface: "{{ ansible_default_ipv4.interface }}"
+    - import_role:
+        name: ironic-enroll-dynamic
+        private: True
+      delegate_to: opnfv
+    - import_role:
+        name: ironic-inspect-node
+        private: True
+      delegate_to: opnfv
+      when: inspect_nodes | default('false') | bool == true
+    - import_role:
+        name: bifrost-configdrives-dynamic
+        private: True
+      delegate_to: opnfv
+    - import_role:
+        name: bifrost-deploy-nodes-dynamic
+        private: True
+      delegate_to: opnfv
   environment:
     http_proxy: "{{ lookup('env','http_proxy') }}"
     https_proxy: "{{ lookup('env','https_proxy') }}"
@@ -127,7 +160,13 @@
 - hosts: baremetal
   name: "Deploy machines."
   become: no
-  connection: local
   serial: 1
-  roles:
-    - role: bifrost-prepare-for-test-dynamic
+  gather_facts: False
+  tasks:
+      #- name: Gathering facts
+      #setup:
+      #delegate_to: opnfv
+      #delegate_facts: False
+    - import_role:
+        name: bifrost-prepare-for-test-dynamic
+      delegate_to: opnfv
diff --git a/xci/infra/bifrost/playbooks/bootstrap-bifrost.yml b/xci/infra/bifrost/playbooks/xci-create-virtual.yml
similarity index 60%
rename from xci/infra/bifrost/playbooks/bootstrap-bifrost.yml
rename to xci/infra/bifrost/playbooks/xci-create-virtual.yml
index 2153b3b3..043907fe 100644
--- a/xci/infra/bifrost/playbooks/bootstrap-bifrost.yml
+++ b/xci/infra/bifrost/playbooks/xci-create-virtual.yml
@@ -1,29 +1,42 @@
 ---
 # SPDX-license-identifier: Apache-2.0
 ##############################################################################
-# Copyright (c) 2017 Ericsson AB and others.
+# Copyright (c) 2018 SUSE LINUX GmbH.
 # All rights reserved. This program and the accompanying materials
 # are made available under the terms of the Apache License, Version 2.0
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
-- hosts: localhost
-  connection: local
-  gather_facts: true
+
+- hosts: deployment_host
+  name: "Bootstrap XCI hardware resources and prepare provisioning environment"
+  gather_facts: yes
   vars_files:
+    - "{{ xci_path }}/xci/var/pdf.yml"
+    - "{{ xci_path }}/xci/var/opnfv_vm.yml"
     - "{{ xci_path }}/xci/var/opnfv.yml"
   pre_tasks:
     - name: Load distribution variables
       include_vars:
         file: "{{ xci_path }}/xci/var/{{ ansible_os_family }}.yml"
   roles:
+    - role: create-vm-nodes
+      become: yes
     - role: clone-repository
       project: "opnfv/bifrost"
       repo: "{{ openstack_bifrost_git_url }}"
       dest: "{{ xci_cache }}/repos/bifrost"
       version: "{{ openstack_bifrost_version }}"
-
   tasks:
+    - name: Wait for host to come back to life
+      local_action:
+        module: wait_for
+        host: "{{ opnfv_vm_ip }}"
+        delay: 15
+        state: started
+        port: 22
+        connect_timeout: 10
+        timeout: 180
     - name: Load distribution variables
       include_vars:
         file: "{{ xci_path }}/xci/var/{{ ansible_os_family }}.yml"
@@ -40,3 +53,12 @@
       copy:
         src: "{{ xci_path}}/xci/infra/bifrost/"
         dest: "{{ xci_cache }}/repos/bifrost"
+    - name: "Ensure /etc/hosts has good defaults"
+      lineinfile:
+        dest: "/etc/hosts"
+        regexp: "{{ item.regexp }}.*({{ ansible_hostname }}|localhost).*"
+        line: "{{ item.contents }}"
+      become: yes
+      with_items:
+        - { regexp: '^127\.0\.0\.1', contents: '127.0.0.1 {{ ansible_hostname }} {{ ansible_fqdn }} localhost' }
+        - { regexp: '^::1', contents: '::1 {{ ansible_hostname }} {{ ansible_fqdn }} localhost ipv6-localhost ipv6-loopback' }
diff --git a/xci/infra/bifrost/playbooks/xci-prepare-virtual.yml b/xci/infra/bifrost/playbooks/xci-prepare-virtual.yml
new file mode 100644
index 00000000..b4ad8c0c
--- /dev/null
+++ b/xci/infra/bifrost/playbooks/xci-prepare-virtual.yml
@@ -0,0 +1,93 @@
+- name: Prepare deployment host
+  hosts: deployment_host
+  gather_facts: True
+  tasks:
+    - name: Ensure common private key has correct permissions
+      file:
+        path: "{{ xci_path }}/xci/scripts/vm/id_rsa_for_dib"
+        mode: "0600"
+
+    - name: Remove host from known_hosts file if necessary
+      shell:
+        ssh-keygen -R {{ hostvars['opnfv'].ip }}
+      failed_when: false
+
+- name: Prepare the OPNFV host
+  hosts: opnfv
+  gather_facts: True
+  vars_files:
+    - "{{ xci_path }}/xci/var/opnfv.yml"
+  tasks:
+    - name: Copy bifrost inventory file
+      copy:
+        src: /tmp/baremetal.json
+        dest: /tmp/baremetal.json
+
+    - name: Configure SSH key for devuser
+      user:
+        name: devuser
+        generate_ssh_key: yes
+        ssh_key_bits: 2048
+        ssh_key_comment: xci
+        ssh_key_type: rsa
+        state: present
+
+    - name: Determine local user
+      become: no
+      local_action: command whoami
+      changed_when: False
+      register: _ansible_user
+
+    - name: Fetch local SSH key
+      delegate_to: localhost
+      become: no
+      slurp:
+        src: "/home/{{ _ansible_user.stdout }}/.ssh/id_rsa.pub"
+      register: _local_ssh_key
+
+    - name: "Configure {{ inventory_hostname }} authorized_keys file (devuser)"
+      authorized_key:
+        exclusive: no
+        user: devuser
+        state: present
+        manage_dir: yes
+        key: "{{ _local_ssh_key['content'] | b64decode }}"
+        comment: "deployer's key"
+
+    - name: "Configure {{ inventory_hostname }} authorized_keys file (root)"
+      authorized_key:
+        exclusive: no
+        user: root
+        state: present
+        manage_dir: yes
+        key: "{{ _local_ssh_key['content'] | b64decode }}"
+        comment: "deployer's key"
+      become: yes
+
+    - name: Ensure /httpboot directory exists
+      file:
+        path: /httpboot
+        state: directory
+      become: yes
+
+    - name: Copy original qcow2 image to OPNFV VM
+      synchronize:
+        src: "{{ xci_cache }}/{{ item }}"
+        dest: /httpboot/
+        recursive: yes
+        delete: yes
+      with_items:
+        - "deployment_image.qcow2"
+        - "deployment_image.qcow2.sha256.txt"
+      become: yes
+
+    - name: Configure DNS on openSUSE
+      block:
+        - stat:
+            path: /etc/resolv.conf.netconfig
+          register: _resolv_conf_netconfig
+        - shell: |
+            mv /etc/resolv.conf.netconfig /etc/resolv.conf
+          become: yes
+          when: _resolv_conf_netconfig.stat.exists
+      when: ansible_pkg_mgr == 'zypper'
diff --git a/xci/infra/bifrost/scripts/bifrost-env.sh b/xci/infra/bifrost/scripts/bifrost-env.sh
new file mode 100755
index 00000000..72d1dafe
--- /dev/null
+++ b/xci/infra/bifrost/scripts/bifrost-env.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+# SPDX-license-identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2016 Ericsson AB and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# dib configuration
+case ${XCI_DISTRO,,} in
+    # These should ideally match the CI jobs
+    ubuntu)
+        export DIB_OS_RELEASE="${DIB_OS_RELEASE:-xenial}"
+        export DIB_OS_ELEMENT="${DIB_OS_ELEMENT:-ubuntu-minimal}"
+        export DIB_OS_PACKAGES="${DIB_OS_PACKAGES:-vlan,vim,less,bridge-utils,language-pack-en,iputils-ping,rsyslog,curl,iptables}"
+        ;;
+    centos)
+        export DIB_OS_RELEASE="${DIB_OS_RELEASE:-7}"
+        export DIB_OS_ELEMENT="${DIB_OS_ELEMENT:-centos-minimal}"
+        export DIB_OS_PACKAGES="${DIB_OS_PACKAGES:-vim,less,bridge-utils,iputils,rsyslog,curl,iptables}"
+        ;;
+    opensuse)
+        export DIB_OS_RELEASE="${DIB_OS_RELEASE:-42.3}"
+        export DIB_OS_ELEMENT="${DIB_OS_ELEMENT:-opensuse-minimal}"
+        export DIB_OS_PACKAGES="${DIB_OS_PACKAGES:-vim,less,bridge-utils,iputils,rsyslog,curl,iptables}"
+        ;;
+esac
+
+export BIFROST_INVENTORY_SOURCE=/tmp/baremetal.json
+
+pip install -q --upgrade -r "${XCI_CACHE}/repos/bifrost/requirements.txt"
diff --git a/xci/infra/bifrost/scripts/bifrost-provision.sh b/xci/infra/bifrost/scripts/bifrost-provision.sh
deleted file mode 100755
index 940e9439..00000000
--- a/xci/infra/bifrost/scripts/bifrost-provision.sh
+++ /dev/null
@@ -1,176 +0,0 @@
-#!/bin/bash
-# SPDX-license-identifier: Apache-2.0
-##############################################################################
-# Copyright (c) 2016 Ericsson AB and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-set -eu
-set -o pipefail
-
-# This is normally passed from the XCI deployment script but
-# we also need it here for the bifrost jobs which run outside of XCI
-export XCI_PATH="${XCI_PATH:-$(git rev-parse --show-toplevel)}"
-# Declare our virtualenv
-export XCI_VENV="${XCI_VENV:-${XCI_PATH}/venv/}"
-export XCI_DISTRO=${XCI_DISTRO:-$(source /etc/os-release &>/dev/null || source /usr/lib/os-release &>/dev/null; echo ${ID,,})}
-
-export PYTHONUNBUFFERED=1
-SCRIPT_HOME="$(cd "$(dirname "$0")" && pwd)"
-BIFROST_HOME=$SCRIPT_HOME/..
-ENABLE_VENV="true"
-export VENV=${XCI_VENV}
-PROVISION_WAIT_TIMEOUT=${PROVISION_WAIT_TIMEOUT:-3600}
-# This is normally exported by XCI env but we should initialize it here
-# in case we run this script on its own for debug purposes
-XCI_ANSIBLE_PARAMS=${XCI_ANSIBLE_PARAMS:-}
-# Ironic SHAs
-BIFROST_IRONIC_INSPECTOR_VERSION=${BIFROST_IRONIC_INSPECTOR_VERSION:-master}
-BIFROST_IRONIC_INSPECTOR_CLIENT_VERSION=${BIFROST_IRONIC_INSPECTOR_CLIENT_VERSION:-master}
-BIFROST_IRONIC_CLIENT_VERSION=${BIFROST_IRONIC_CLIENT_VERSION:-master}
-BIFROST_IRONIC_VERSION=${BIFROST_IRONIC_VERSION:-master}
-
-# set UPPER_CONSTRAINTS_FILE since it is needed in order to limit libvirt-python to 4.0.0
-export UPPER_CONSTRAINTS_FILE=https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt
-
-# Ensure the right inventory files is used based on branch
-CURRENT_BIFROST_BRANCH=$(git rev-parse --abbrev-ref HEAD)
-if [ $CURRENT_BIFROST_BRANCH = "master" ]; then
-    BAREMETAL_DATA_FILE=${BAREMETAL_DATA_FILE:-'/tmp/baremetal.json'}
-    INVENTORY_FILE_FORMAT="baremetal_json_file"
-else
-    BAREMETAL_DATA_FILE=${BAREMETAL_DATA_FILE:-'/tmp/baremetal.csv'}
-    INVENTORY_FILE_FORMAT="baremetal_csv_file"
-fi
-export BIFROST_INVENTORY_SOURCE=$BAREMETAL_DATA_FILE
-
-# Default settings for VMs
-export TEST_VM_NUM_NODES=${TEST_VM_NUM_NODES:-3}
-export TEST_VM_NODE_NAMES=${TEST_VM_NODE_NAMES:-"opnfv controller00 compute00"}
-export VM_DOMAIN_TYPE=${VM_DOMAIN_TYPE:-kvm}
-export VM_CPU=${VM_CPU:-4}
-export VM_DISK=${VM_DISK:-100}
-export VM_MEMORY_SIZE=${VM_MEMORY_SIZE:-8192}
-export VM_DISK_CACHE=${VM_DISK_CACHE:-unsafe}
-
-# Settings for bifrost
-TEST_PLAYBOOK="opnfv-virtual.yaml"
-USE_INSPECTOR=true
-USE_CIRROS=false
-TESTING_USER=root
-DOWNLOAD_IPA=true
-CREATE_IPA_IMAGE=false
-INSPECT_NODES=true
-INVENTORY_DHCP=false
-INVENTORY_DHCP_STATIC_IP=false
-WRITE_INTERFACES_FILE=true
-
-# Settings for console access
-export DIB_DEV_USER_PWDLESS_SUDO=yes
-export DIB_DEV_USER_PASSWORD=devuser
-
-# Additional dib elements
-export EXTRA_DIB_ELEMENTS=${EXTRA_DIB_ELEMENTS:-"openssh-server"}
-
-# dib configuration
-case ${XCI_DISTRO,,} in
-    # These should ideally match the CI jobs
-    ubuntu)
-        export DIB_OS_RELEASE="${DIB_OS_RELEASE:-xenial}"
-        export DIB_OS_ELEMENT="${DIB_OS_ELEMENT:-ubuntu-minimal}"
-        export DIB_OS_PACKAGES="${DIB_OS_PACKAGES:-vlan,vim,less,bridge-utils,language-pack-en,iputils-ping,rsyslog,curl,iptables}"
-        ;;
-    centos)
-        export DIB_OS_RELEASE="${DIB_OS_RELEASE:-7}"
-        export DIB_OS_ELEMENT="${DIB_OS_ELEMENT:-centos-minimal}"
-        export DIB_OS_PACKAGES="${DIB_OS_PACKAGES:-vim,less,bridge-utils,iputils,rsyslog,curl,iptables}"
-        ;;
-    opensuse)
-        export DIB_OS_RELEASE="${DIB_OS_RELEASE:-42.3}"
-        export DIB_OS_ELEMENT="${DIB_OS_ELEMENT:-opensuse-minimal}"
-        export DIB_OS_PACKAGES="${DIB_OS_PACKAGES:-vim,less,bridge-utils,iputils,rsyslog,curl,iptables}"
-        ;;
-esac
-
-# Copy the OS images if found
-if [[ -e ${XCI_PATH}/deployment_image.qcow2 ]]; then
-	sudo mkdir -p /httpboot
-	sudo mv ${XCI_PATH}/deployment_image.qcow2* /httpboot/
-fi
-
-# Install missing dependencies. Use sudo since for bifrost jobs
-# the venv is not ready yet.
-if [[ -n ${VIRTUAL_ENV:-} ]]; then
-    _sudo=""
-else
-    virtualenv --quiet --no-site-packages ${XCI_VENV}
-    set +u
-    source ${XCI_VENV}/bin/activate
-    set -u
-    _sudo="sudo -H -E"
-fi
-${_sudo} pip install -q --upgrade -r "$(dirname $0)/../requirements.txt"
-
-# Change working directory
-cd $BIFROST_HOME/playbooks
-
-# NOTE(hwoarang): Disable selinux as we are hitting issues with it from time to
-# time. Remove this when Centos7 is a proper gate on bifrost so we know that
-# selinux works as expected.
-if [[ -e /etc/centos-release ]]; then
-    echo "*************************************"
-    echo "WARNING: Disabling selinux on CentOS7"
-    echo "*************************************"
-    sudo setenforce 0
-fi
-
-# Create the VMS
-ansible-playbook ${XCI_ANSIBLE_PARAMS} \
-       -i inventory/localhost \
-       test-bifrost-create-vm.yaml \
-       -e test_vm_num_nodes=${TEST_VM_NUM_NODES} \
-       -e test_vm_cpu='host-model' \
-       -e test_vm_memory_size=${VM_MEMORY_SIZE} \
-       -e enable_venv=${ENABLE_VENV} \
-       -e test_vm_domain_type=${VM_DOMAIN_TYPE} \
-       -e ${INVENTORY_FILE_FORMAT}=${BAREMETAL_DATA_FILE}
-
-# Execute the installation and VM startup test
-ansible-playbook ${XCI_ANSIBLE_PARAMS} \
-    -i inventory/bifrost_inventory.py \
-    ${TEST_PLAYBOOK} \
-    -e use_cirros=${USE_CIRROS} \
-    -e testing_user=${TESTING_USER} \
-    -e test_vm_num_nodes=${TEST_VM_NUM_NODES} \
-    -e test_vm_cpu='host-model' \
-    -e inventory_dhcp=${INVENTORY_DHCP} \
-    -e inventory_dhcp_static_ip=${INVENTORY_DHCP_STATIC_IP} \
-    -e enable_venv=${ENABLE_VENV} \
-    -e enable_inspector=${USE_INSPECTOR} \
-    -e inspect_nodes=${INSPECT_NODES} \
-    -e download_ipa=${DOWNLOAD_IPA} \
-    -e create_ipa_image=${CREATE_IPA_IMAGE} \
-    -e write_interfaces_file=${WRITE_INTERFACES_FILE} \
-    -e ipv4_gateway=192.168.122.1 \
-    -e wait_timeout=${PROVISION_WAIT_TIMEOUT} \
-    -e enable_keystone=false \
-    -e ironicinspector_source_install=true \
-    -e ironicinspector_git_branch=${BIFROST_IRONIC_INSPECTOR_VERSION} \
-    -e ironicinspectorclient_source_install=true \
-    -e ironicinspectorclient_git_branch=${BIFROST_IRONIC_INSPECTOR_CLIENT_VERSION} \
-    -e ironicclient_source_install=true \
-    -e ironicclient_git_branch=${BIFROST_IRONIC_CLIENT_VERSION} \
-    -e ironic_git_branch=${BIFROST_IRONIC_VERSION} \
-    -e use_prebuilt_images=${BIFROST_USE_PREBUILT_IMAGES} \
-    -e xci_distro=${XCI_DISTRO}
-EXITCODE=$?
-
-if [ $EXITCODE != 0 ]; then
-    echo "************************************"
-    echo "Provisioning failed. See logs folder"
-    echo "************************************"
-fi
-
-exit $EXITCODE
diff --git a/xci/infra/bifrost/vars/debian.yml b/xci/infra/bifrost/vars/debian.yml
new file mode 100644
index 00000000..95303b38
--- /dev/null
+++ b/xci/infra/bifrost/vars/debian.yml
@@ -0,0 +1,19 @@
+---
+# SPDX-license-identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2018 SUSE Linux GmbH.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+bifrost_required_devel_packages:
+  - gcc
+  - libffi-dev
+  - libssl-dev
+  - lsb-release
+  - make
+  - net-tools
+  - libpython-dev
+  - wget
+  - iptables
diff --git a/xci/infra/bifrost/vars/redhat.yml b/xci/infra/bifrost/vars/redhat.yml
new file mode 100644
index 00000000..056c4d61
--- /dev/null
+++ b/xci/infra/bifrost/vars/redhat.yml
@@ -0,0 +1,19 @@
+---
+# SPDX-license-identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2018 SUSE Linux GmbH.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+bifrost_required_devel_packages:
+  - gcc
+  - libffi-devel
+  - openssl-devel
+  - redhat-lsb
+  - make
+  - net-tools
+  - python-devel
+  - wget
+  - iptables
diff --git a/xci/infra/bifrost/vars/suse.yml b/xci/infra/bifrost/vars/suse.yml
new file mode 100644
index 00000000..8e2e9041
--- /dev/null
+++ b/xci/infra/bifrost/vars/suse.yml
@@ -0,0 +1,19 @@
+---
+# SPDX-license-identifier: Apache-2.0
+##############################################################################
+# Copyright (c) 2018 SUSE Linux GmbH.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+bifrost_required_devel_packages:
+  - gcc
+  - libffi-devel
+  - libopenssl-devel
+  - make
+  - net-tools
+  - python-devel
+  - python-xml
+  - wget
+  - iptables
diff --git a/xci/playbooks/roles/create-vm-nodes/defaults/main.yml b/xci/playbooks/roles/create-vm-nodes/defaults/main.yml
index 90ee6e5c..6ac266a5 100644
--- a/xci/playbooks/roles/create-vm-nodes/defaults/main.yml
+++ b/xci/playbooks/roles/create-vm-nodes/defaults/main.yml
@@ -6,7 +6,7 @@ baremetal_json_file: '/tmp/baremetal.json'
 vm_nic: "virtio"
 vm_groups: {}
 vm_default_groups: "{{ lookup('env', 'DEFAULT_HOST_GROUPS').split() | default(['baremetal'], true) }}"
-vm_disk_cache: "{{ lookup('env', 'VM_DISK_CACHE') | default('unsafe', true) }}"
+vm_disk_cache: unsafe
 node_names: "{{ lookup('env', 'NODE_NAMES').split() }}"
 
 # NOTE(pas-ha) name and default are chosen to be the same
-- 
2.16.6