From fb4973f833409dd6973aa08d50ae4995548a5701 Mon Sep 17 00:00:00 2001
From: Mark Goddard <mark@stackhpc.com>
Date: Wed, 15 Mar 2017 13:52:25 +0000
Subject: [PATCH] Use shade role in test playbooks

---
 ansible/test-image-centos-cloud.yml | 24 +++++++++++-------------
 ansible/test-image.yml              | 22 +++-------------------
 ansible/test-infra.yml              | 23 ++++-------------------
 ansible/test-keypair.yml            | 22 +++-------------------
 4 files changed, 21 insertions(+), 70 deletions(-)

diff --git a/ansible/test-image-centos-cloud.yml b/ansible/test-image-centos-cloud.yml
index aefb6cc02..f153a16a1 100644
--- a/ansible/test-image-centos-cloud.yml
+++ b/ansible/test-image-centos-cloud.yml
@@ -1,19 +1,11 @@
 ---
-- hosts: seed[0]
+- name: Ensure CentOS cloud image is registered with Glance
+  hosts: controllers[0]
   vars:
-    openstack_auth:
-      auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}"
-      username: "{{ lookup('env', 'OS_USERNAME') }}"
-      password: "{{ lookup('env', 'OS_PASSWORD') }}"
-      project_name: "{{ lookup('env', 'OS_PROJECT_NAME') }}"
-      project_domain_name: "{{ lookup('env', 'OS_PROJECT_DOMAIN_NAME') }}"
-      user_domain_name: "{{ lookup('env', 'OS_USER_DOMAIN_NAME') }}"
+    shade_venv: "{{ ansible_env['PWD'] }}/shade-venv"
+  roles:
+    - role: shade
   tasks:
-    - name: Ensure OpenStack shade module is installed
-      pip:
-        name: shade
-      become: True
-
     - name: Ensure image download directory exists
       file:
         path: "{{ image_cache_path }}"
@@ -24,6 +16,12 @@
         url: http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2
         dest: "{{ image_cache_path }}/CentOS-7-x86_64-GenericCloud.qcow2"
 
+    # Note that setting this via a play or task variable seems to not
+    # evaluate the Jinja variable reference, so we use set_fact.
+    - name: Update the Ansible python interpreter fact to point to the shade virtualenv
+      set_fact:
+        ansible_python_interpreter: "{{ shade_venv }}/bin/python"
+
     - name: Ensure test deployment image is registered with Glance
       os_image:
         auth: "{{ openstack_auth }}"
diff --git a/ansible/test-image.yml b/ansible/test-image.yml
index bcd973894..cefa3639f 100644
--- a/ansible/test-image.yml
+++ b/ansible/test-image.yml
@@ -1,14 +1,7 @@
 ---
 - name: Ensure user images are built and registered with Glance
-  hosts: seed
+  hosts: controllers[0]
   vars:
-    openstack_auth:
-      auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}"
-      username: "{{ lookup('env', 'OS_USERNAME') }}"
-      password: "{{ lookup('env', 'OS_PASSWORD') }}"
-      project_name: "{{ lookup('env', 'OS_PROJECT_NAME') }}"
-      project_domain_name: "{{ lookup('env', 'OS_PROJECT_DOMAIN_NAME') }}"
-      user_domain_name: "{{ lookup('env', 'OS_USER_DOMAIN_NAME') }}"
     image_build_dir: "{{ ansible_user_dir }}/images/dib"
     image_name: centos7
     image_os_element: centos7
@@ -24,6 +17,8 @@
     image_extra_elements: []
     image_elements: "{{ image_base_elements + (image_whole_disk_elements if image_is_whole_disk|bool else image_partition_elements) + image_extra_elements }}"
     shade_venv: "{{ ansible_env['PWD'] }}/shade-venv"
+  roles:
+    - role: shade
   tasks:
     - name: Ensure diskimage-builder package is installed
       yum:
@@ -31,17 +26,6 @@
         state: installed
       become: True
 
-    - name: Ensure pip is installed
-      pip:
-        name: pip
-        state: latest
-        virtualenv: "{{ shade_venv }}"
-
-    - name: Ensure OpenStack shade module is installed
-      pip:
-        name: shade
-        virtualenv: "{{ shade_venv }}"
-
     - name: Ensure image build directory exists
       file:
         path: "{{ image_build_dir }}"
diff --git a/ansible/test-infra.yml b/ansible/test-infra.yml
index cb543c47f..c8126132a 100644
--- a/ansible/test-infra.yml
+++ b/ansible/test-infra.yml
@@ -1,27 +1,12 @@
 ---
-- hosts: seed
+- name: Ensure test infrastructure is registered
+  hosts: controllers[0]
   vars:
-    openstack_auth:
-      auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}"
-      username: "{{ lookup('env', 'OS_USERNAME') }}"
-      password: "{{ lookup('env', 'OS_PASSWORD') }}"
-      project_name: "{{ lookup('env', 'OS_PROJECT_NAME') }}"
-      project_domain_name: "{{ lookup('env', 'OS_PROJECT_DOMAIN_NAME') }}"
-      user_domain_name: "{{ lookup('env', 'OS_USER_DOMAIN_NAME') }}"
     shade_venv: "{{ ansible_env['PWD'] }}/shade-venv"
     test_image_cache_path: "{{ ansible_env['PWD'] }}/images"
+  roles:
+    - role: shade
   tasks:
-    - name: Ensure pip is installed
-      pip:
-        name: pip
-        state: latest
-        virtualenv: "{{ shade_venv }}"
-
-    - name: Ensure OpenStack shade module is installed
-      pip:
-        name: shade
-        virtualenv: "{{ shade_venv }}"
-
     - name: Ensure image download directory exists
       file:
         path: "{{ test_image_cache_path }}"
diff --git a/ansible/test-keypair.yml b/ansible/test-keypair.yml
index 6455b3d7b..ab986acde 100644
--- a/ansible/test-keypair.yml
+++ b/ansible/test-keypair.yml
@@ -1,28 +1,12 @@
 ---
 - name: Ensure user SSH keypair is registered with Nova
-  hosts: seed
+  hosts: controllers[0]
   vars:
-    openstack_auth:
-      auth_url: "{{ lookup('env', 'OS_AUTH_URL') }}"
-      username: "{{ lookup('env', 'OS_USERNAME') }}"
-      password: "{{ lookup('env', 'OS_PASSWORD') }}"
-      project_name: "{{ lookup('env', 'OS_PROJECT_NAME') }}"
-      project_domain_name: "{{ lookup('env', 'OS_PROJECT_DOMAIN_NAME') }}"
-      user_domain_name: "{{ lookup('env', 'OS_USER_DOMAIN_NAME') }}"
     public_key_path: "{{ ssh_public_key_path }}"
     shade_venv: "{{ ansible_env['PWD'] }}/shade-venv"
+  roles:
+    - role: shade
   tasks:
-    - name: Ensure pip is installed
-      pip:
-        name: pip
-        state: latest
-        virtualenv: "{{ shade_venv }}"
-
-    - name: Ensure OpenStack shade module is installed
-      pip:
-        name: shade
-        virtualenv: "{{ shade_venv }}"
-
     # Note that setting this via a play or task variable seems to not
     # evaluate the Jinja variable reference, so we use set_fact.
     - name: Update the Ansible python interpreter fact to point to the shade virtualenv