Migrate devstack images to Ansible provisioners 35/81835/5
authorAnil Belur <abelur@linuxfoundation.org>
Tue, 14 May 2019 01:37:39 +0000 (11:37 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Tue, 14 May 2019 02:28:04 +0000 (12:28 +1000)
Migrate the packer provisioners to use Ansible playbooks.
Remove the shell scripts used to provision custom devstack
{pre-pip-{queens,rocky}} images.

Change-Id: I42a114db01208b96a0fd9116a4404bdd61688376
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
packer/provision/devstack-pre-pip.sh [deleted file]
packer/provision/devstack-pre-pip.yaml [new file with mode: 0644]
packer/provision/devstack.sh [deleted file]
packer/provision/devstack.yaml [new file with mode: 0644]
packer/templates/devstack-pre-pip-queens.json
packer/templates/devstack-pre-pip-rocky.json
packer/templates/devstack.json

diff --git a/packer/provision/devstack-pre-pip.sh b/packer/provision/devstack-pre-pip.sh
deleted file mode 100644 (file)
index 8a910d9..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/bin/bash
-
-# force any errors to cause the script and job to end in failure
-set -xeu -o pipefail
-
-# Install xpath
-yum install -y perl-XML-XPath python-pip
-
-# install crudini command line tool for editing config files
-yum install -y crudini
-
-echo '---> Installing non-baseline requirements'
-yum install -y deltarpm nc python{,-{crypto,devel,lxml,setuptools}} \
-    @development {lib{xml2,xslt,ffi},openssl}-devel git wget
-
-echo '---> Updating net link setup'
-if [ ! -f /etc/udev/rules.d/80-net-setup-link.rules ]; then
-    ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules
-fi
-
-echo '---> Pre-installing yum and pip packages'
-projs="requirements keystone glance cinder neutron nova horizon"
-# shellcheck disable=SC2154
-branch=${os_branch}
-# strip the "stable" off of the branch
-branch_name=$(cut -d'/' -f2 <<< "${branch}")
-
-# Do not upgrade pip to v10. v10 does not allow uninstalling
-# distutils installed packages. This fails the openstack pip installs
-# below when it attempts to uninstall packages.
-# devstack patch that is trying to get pip 10 working:
-# https://review.openstack.org/#/c/561597/
-# wget https://bootstrap.pypa.io/get-pip.py
-# python get-pip.py
-
-mkdir tmp
-cd tmp
-
-git clone https://github.com/openstack-dev/devstack.git
-(cd devstack && git checkout "${branch}")
-sed -e 's/#.*//' devstack/files/rpms/general | xargs yum install -y
-
-base_url=https://github.com/openstack/
-for proj in $projs
-do
-    git clone "${base_url}${proj}"
-    (cd "${proj}" && git checkout "${branch}")
-    pip install -c requirements/upper-constraints.txt -e "${proj}"
-    pip install -c requirements/upper-constraints.txt -r "${proj}/test-requirements.txt"
-done
-
-echo '---> Installing openvswitch from relevant openstack branch'
-yum install -y "centos-release-openstack-${branch_name}"
-
-# install 2.8.2 for queens.
-# 2.9.0 is the current version in openstack-queens, but it is buggy.
-# Remove this when https://review.rdoproject.org/r/#/c/13839/ merges and 2.9.2 is in the repo.
-yum repolist
-yum --showduplicates list openvswitch
-if [ "${branch}" == "stable/queens" ]; then
-    yum install -y --nogpgcheck openvswitch-2.8.2-1.el7
-else
-    yum install -y --nogpgcheck openvswitch
-fi
-cd "$OLDPWD"
-rm -fr tmp
-
-# vim: sw=4 ts=4 sts=4 et :
diff --git a/packer/provision/devstack-pre-pip.yaml b/packer/provision/devstack-pre-pip.yaml
new file mode 100644 (file)
index 0000000..b70b2bd
--- /dev/null
@@ -0,0 +1,135 @@
+---
+- import_playbook: ../common-packer/provision/baseline.yaml
+
+- hosts: all
+  become_user: root
+  become_method: sudo
+
+  pre_tasks:
+    - include_role: name=lfit.system-update
+
+  tasks:
+    - name: 'Install devstack dependencies'
+      block:
+        - name: Install xpath dependencies
+          yum:
+            name:
+              - perl-XML-XPath
+              - python-pip
+              - crudini
+            state: present
+          become: true
+        - name: Install non-baseline requirements
+          yum:
+            name:
+              - deltarpm
+              - python
+              - python-crypto
+              - python-devel
+              - python-lxml
+              - python-setuptools
+              - libxml2-devel
+              - libxslt-devel
+              - libffi-devel
+              - openssl-devel
+              - "@development"
+            state: present
+          become: true
+        - name: check if net link setup exists
+          stat:
+            path: /etc/udev/rules.d/80-net-setup-link.rules
+          register: rules_file_exists
+        - name: Update net link setup
+          file:
+            src: /dev/null
+            dest: /etc/udev/rules.d/80-net-setup-link.rules
+            state: link
+            force: yes
+          become: true
+          when: rules_file_exists.stat.exists == true
+    - name: 'Pre-Install yum and pip packages'
+      block:
+        - name: Create /tmp/devstack directory
+          file:
+            path: /tmp/devstack
+            state: directory
+            mode: 0755
+        - name: Fetch openstack devstack-dev repo
+          git:
+            repo: https://github.com/openstack-dev/devstack.git
+            dest: /tmp/devstack
+            version: '{{ os_branch }}'
+        - name: "Read openstack devstack dependencies"
+          shell: "sed -e 's/#.*//' /tmp/devstack/files/rpms/general"
+          register: sed_output
+          args:
+            warn: False
+        - name: "Install non-baseline requirements for {{ os_branch }}"
+          yum: 'name={{item}} state=present'
+          with_items:
+            - "{{ sed_output.stdout_lines }}"
+          become: true
+        - name: git clone openstack core projects
+          git: repo='https://github.com/openstack/{{ item }}.git'
+               dest='/tmp/devstack/{{ item }}'
+               version='{{ os_branch }}'
+          with_items:
+            - requirements
+            - keystone
+            - glance
+            - cinder
+            - neutron
+            - nova
+            - horizon
+        - name: Install pip dependencies
+          shell: |
+            cd "{{ item }}"
+            git branch -a
+            cd ..
+            pwd
+            pip install -c requirements/upper-constraints.txt -e "{{ item }}"
+            pip install -c requirements/upper-constraints.txt -r "{{ item }}/test-requirements.txt"
+            # ignore non-zero return code
+            exit 0
+          args:
+            chdir: /tmp/devstack
+            warn: False
+          with_items:
+            - requirements
+            - keystone
+            - glance
+            - cinder
+            - neutron
+            - nova
+            - horizon
+          become: true
+
+    - name: 'Install openvswitch from relevant openstack branch'
+      block:
+        - name: 'Install CentOS openstack release {{ rdo_branch }}'
+          yum:
+            name: 'centos-release-openstack-{{ rdo_branch }}'
+            state: present
+          become: true
+        - name: 'Install openvswitch 2.8.2 for stable/queens'
+          yum:
+            name: openvswitch-2.8.2-1.el7
+            state: present
+            disable_gpg_check: yes
+          when: rdo_branch == 'queens'
+          become: true
+        - name: 'Install openvswitch latest for stable/rocky'
+          yum:
+            name: openvswitch
+            state: present
+            disable_gpg_check: yes
+          when: rdo_branch == 'rocky'
+          become: true
+
+    - name: 'Cleanup devstack directory'
+      block:
+        - name: "Removing /tmp/devstack"
+          file:
+            path: /tmp/devstack
+            state: absent
+          become: true
diff --git a/packer/provision/devstack.sh b/packer/provision/devstack.sh
deleted file mode 100644 (file)
index a420da9..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/bin/bash
-
-# force any errors to cause the script and job to end in failure
-set -xeu -o pipefail
-
-# Install xpath
-yum install -y perl-XML-XPath python-pip
-
-# install crudini command line tool for editing config files
-yum install -y crudini
-
-echo '---> Installing non-baseline requirements'
-yum install -y deltarpm python{,-{crypto,devel,lxml,setuptools}} \
-    @development {lib{xml2,xslt,ffi},openssl}-devel
-
-echo '---> Updating net link setup'
-if [ ! -f /etc/udev/rules.d/80-net-setup-link.rules ]; then
-    ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules
-fi
-
-echo "***************************************************"
-echo "*   PLEASE RELOAD THIS VAGRANT BOX BEFORE USE     *"
-echo "***************************************************"
-
-# vim: sw=4 ts=4 sts=4 et :
diff --git a/packer/provision/devstack.yaml b/packer/provision/devstack.yaml
new file mode 100644 (file)
index 0000000..46e41c6
--- /dev/null
@@ -0,0 +1,49 @@
+---
+- import_playbook: ../common-packer/provision/baseline.yaml
+
+- hosts: all
+  become_user: root
+  become_method: sudo
+
+  pre_tasks:
+    - include_role: name=lfit.system-update
+
+  tasks:
+    - name: 'Install devstack dependencies'
+      block:
+        - name: Install xpath dependencies
+          yum:
+            name:
+              - perl-XML-XPath
+              - python-pip
+              - crudini
+            state: present
+          become: true
+        - name: Installing non-baseline requirements
+          yum:
+            name:
+              - deltarpm
+              - python
+              - python-crypto
+              - python-devel
+              - python-lxml
+              - python-setuptools
+              - libxml2-devel
+              - libxslt-devel
+              - libffi-devel
+              - openssl-devel
+              - "@development"
+            state: present
+          become: true
+        - name: check if net link setup exists
+          stat:
+            path: /etc/udev/rules.d/80-net-setup-link.rules
+          register: rules_file_exists
+        - name: Update net link setup
+          file:
+            src: /dev/null
+            dest: /etc/udev/rules.d/80-net-setup-link.rules
+            state: link
+            force: yes
+          become: true
+          when: rules_file_exists.stat.exists == true
index 576f7f13790f3fcc2aef480da4a44d42239294e6..367ef8b405c36398979842a990f6c25cf5113ded 100644 (file)
@@ -1,5 +1,6 @@
 {
   "variables": {
+    "ansible_roles_path": ".galaxy",
     "base_image": null,
     "distro": null,
     "cloud_network": null,
   },
   "builders": [
     {
-      "type": "openstack",
-      "region": "ca-ymq-1",
-      "availability_zone": "ca-ymq-2",
-      "ssh_username": "{{user `ssh_user`}}",
-      "ssh_proxy_host": "{{user `ssh_proxy_host`}}",
+      "name": "vexxhost",
       "image_name": "ZZCI - {{user `distro`}} - devstack-queens - {{isotime \"20060102-150405.000\"}}",
       "instance_name": "{{user `distro`}}-devstack-queens-{{uuid}}",
       "source_image_name": "{{user `base_image`}}",
-      "flavor": "v1-standard-1",
+      "type": "openstack",
+      "region": "ca-ymq-1",
+      "availability_zone": "ca-ymq-2",
       "networks": [
         "{{user `cloud_network`}}"
       ],
       "user_data_file": "{{user `cloud_user_data`}}",
+      "ssh_username": "{{user `ssh_user`}}",
+      "ssh_proxy_host": "{{user `ssh_proxy_host`}}",
+      "flavor": "v1-standard-1",
       "metadata": {
         "ci_managed": "yes"
       }
   "provisioners": [
     {
       "type": "shell",
-      "environment_vars": [
-        "os_branch=stable/queens",
-        "rdo_branch=queens"
-      ],
       "scripts": [
-        "provision/baseline.sh",
-        "provision/devstack-pre-pip.sh",
-        "provision/system_reseal_local_env.sh",
-        "provision/system_reseal.sh"
+        "common-packer/provision/install-python.sh"
       ],
       "execute_command": "chmod +x {{ .Path }}; if [ \"$UID\" == \"0\" ]; then {{ .Vars }} '{{ .Path }}'; else {{ .Vars }} sudo -E '{{ .Path }}'; fi"
+    },
+    {
+      "type": "shell-local",
+      "command": "./common-packer/ansible-galaxy.sh {{user `ansible_roles_path`}}"
+    },
+    {
+      "type": "ansible",
+      "playbook_file": "provision/devstack-pre-pip.yaml",
+      "ansible_env_vars": [
+        "ANSIBLE_DEBUG=False",
+        "ANSIBLE_NOCOWS=1",
+        "ANSIBLE_PIPELINING=True",
+        "ANSIBLE_ROLES_PATH={{user `ansible_roles_path`}}",
+        "ANSIBLE_CALLBACK_WHITELIST=profile_tasks",
+        "ANSIBLE_STDOUT_CALLBACK=debug"
+      ],
+      "extra_arguments": [
+        "--extra-vars",
+        "os_branch=stable/queens rdo_branch=queens"
+      ]
     }
   ]
 }
index e892bc314b8c39ad25fc1d19e5bc6f714889051e..7798f97beda3a8c225f48db8ab67529750a6278e 100644 (file)
@@ -1,5 +1,6 @@
 {
   "variables": {
+    "ansible_roles_path": ".galaxy",
     "base_image": null,
     "distro": null,
     "cloud_network": null,
   },
   "builders": [
     {
-      "type": "openstack",
-      "region": "ca-ymq-1",
-      "availability_zone": "ca-ymq-2",
-      "ssh_username": "{{user `ssh_user`}}",
-      "ssh_proxy_host": "{{user `ssh_proxy_host`}}",
+      "name": "vexxhost",
       "image_name": "ZZCI - {{user `distro`}} - devstack-rocky - {{isotime \"20060102-150405.000\"}}",
       "instance_name": "{{user `distro`}}-devstack-rocky-{{uuid}}",
       "source_image_name": "{{user `base_image`}}",
-      "flavor": "v1-standard-1",
+      "type": "openstack",
+      "region": "ca-ymq-1",
+      "availability_zone": "ca-ymq-2",
       "networks": [
         "{{user `cloud_network`}}"
       ],
       "user_data_file": "{{user `cloud_user_data`}}",
+      "ssh_username": "{{user `ssh_user`}}",
+      "ssh_proxy_host": "{{user `ssh_proxy_host`}}",
+      "flavor": "v1-standard-1",
       "metadata": {
         "ci_managed": "yes"
       }
   "provisioners": [
     {
       "type": "shell",
-      "environment_vars": [
-        "os_branch=stable/rocky",
-        "rdo_branch=rocky"
-      ],
       "scripts": [
-        "provision/baseline.sh",
-        "provision/devstack-pre-pip.sh",
-        "provision/system_reseal_local_env.sh",
-        "provision/system_reseal.sh"
+        "common-packer/provision/install-python.sh"
       ],
       "execute_command": "chmod +x {{ .Path }}; if [ \"$UID\" == \"0\" ]; then {{ .Vars }} '{{ .Path }}'; else {{ .Vars }} sudo -E '{{ .Path }}'; fi"
+    },
+    {
+      "type": "shell-local",
+      "command": "./common-packer/ansible-galaxy.sh {{user `ansible_roles_path`}}"
+    },
+    {
+      "type": "ansible",
+      "playbook_file": "provision/devstack-pre-pip.yaml",
+      "ansible_env_vars": [
+        "ANSIBLE_DEBUG=False",
+        "ANSIBLE_NOCOWS=1",
+        "ANSIBLE_PIPELINING=True",
+        "ANSIBLE_ROLES_PATH={{user `ansible_roles_path`}}",
+        "ANSIBLE_CALLBACK_WHITELIST=profile_tasks",
+        "ANSIBLE_STDOUT_CALLBACK=debug"
+      ],
+      "extra_arguments": [
+        "--extra-vars",
+        "os_branch=stable/rocky rdo_branch=rocky"
+      ]
     }
   ]
 }
index 4361140ec622c3b04adead5b62b81a6c5dce4e59..274f95c178738b8c3dd2e4ebb09d413d666a25a4 100644 (file)
@@ -1,5 +1,6 @@
 {
   "variables": {
+    "ansible_roles_path": ".galaxy",
     "base_image": null,
     "distro": null,
     "cloud_network": null,
   },
   "builders": [
     {
-      "type": "openstack",
-      "region": "ca-ymq-1",
-      "availability_zone": "ca-ymq-2",
-      "ssh_username": "{{user `ssh_user`}}",
-      "ssh_proxy_host": "{{user `ssh_proxy_host`}}",
+      "name": "vexxhost",
       "image_name": "ZZCI - {{user `distro`}} - devstack - {{isotime \"20060102-150405.000\"}}",
       "instance_name": "{{user `distro`}}-devstack-{{uuid}}",
       "source_image_name": "{{user `base_image`}}",
-      "flavor": "v1-standard-1",
+      "type": "openstack",
+      "region": "ca-ymq-1",
+      "availability_zone": "ca-ymq-2",
       "networks": [
         "{{user `cloud_network`}}"
       ],
       "user_data_file": "{{user `cloud_user_data`}}",
+      "ssh_username": "{{user `ssh_user`}}",
+      "ssh_proxy_host": "{{user `ssh_proxy_host`}}",
+      "flavor": "v1-standard-1",
       "metadata": {
         "ci_managed": "yes"
       }
     {
       "type": "shell",
       "scripts": [
-        "provision/baseline.sh",
-        "provision/devstack.sh",
-        "provision/system_reseal_local_env.sh",
-        "provision/system_reseal.sh"
+        "common-packer/provision/install-python.sh"
       ],
       "execute_command": "chmod +x {{ .Path }}; if [ \"$UID\" == \"0\" ]; then {{ .Vars }} '{{ .Path }}'; else {{ .Vars }} sudo -E '{{ .Path }}'; fi"
+    },
+    {
+      "type": "shell-local",
+      "command": "./common-packer/ansible-galaxy.sh {{user `ansible_roles_path`}}"
+    },
+    {
+      "type": "ansible",
+      "playbook_file": "provision/devstack.yaml",
+      "ansible_env_vars": [
+        "ANSIBLE_NOCOWS=1",
+        "ANSIBLE_PIPELINING=True",
+        "ANSIBLE_ROLES_PATH={{user `ansible_roles_path`}}",
+        "ANSIBLE_CALLBACK_WHITELIST=profile_tasks",
+        "ANSIBLE_STDOUT_CALLBACK=debug"
+      ]
     }
   ]
 }