Browse code

Merge "New get-devstack-os-environment role"

Zuul authored on 2020/08/19 18:01:10
Showing 5 changed files
... ...
@@ -7,4 +7,6 @@
7 7
       bindep_dir: "{{ zuul_work_dir }}"
8 8
     - test-setup
9 9
     - ensure-tox
10
-    - tox
10
+    - get-devstack-os-environment
11
+    - role: tox
12
+      tox_environment: "{{ os_env_vars|default({}) }}"
... ...
@@ -1,3 +1,5 @@
1 1
 - hosts: all
2 2
   roles:
3
-    - tox
3
+    - get-devstack-os-environment
4
+    - role: tox
5
+      tox_environment: "{{ os_env_vars|default({}) }}"
4 6
new file mode 100644
... ...
@@ -0,0 +1,40 @@
0
+Reads the OS_* variables set by devstack through openrc
1
+for the specified user and project and exports them as
2
+the os_env_vars fact.
3
+
4
+**WARNING**: this role is meant to be used as porting aid
5
+for the non-unified python-<service>client jobs which
6
+are already around, as those clients do not use clouds.yaml
7
+as openstackclient does.
8
+When those clients and their jobs are deprecated and removed,
9
+or anyway when the new code is able to read from clouds.yaml
10
+directly, this role should be removed as well.
11
+
12
+
13
+**Role Variables**
14
+
15
+.. zuul:rolevar:: devstack_base_dir
16
+   :default: /opt/stack
17
+
18
+   The devstack base directory.
19
+
20
+.. zuul:rolevar:: openrc_file
21
+   :default: {{ devstack_base_dir }}/devstack/openrc
22
+
23
+   The location of the generated openrc file.
24
+
25
+.. zuul:rolevar:: openrc_user
26
+   :default: admin
27
+
28
+   The user whose credentials should be retrieved.
29
+
30
+.. zuul:rolevar:: openrc_project
31
+   :default: admin
32
+
33
+   The project (which openrc_user is part of) whose
34
+   access data should be retrieved.
35
+
36
+.. zuul:rolevar:: openrc_enable_export
37
+   :default: false
38
+
39
+   Set it to true to export os_env_vars.
0 40
new file mode 100644
... ...
@@ -0,0 +1,5 @@
0
+devstack_base_dir: "/opt/stack"
1
+openrc_file: "{{ devstack_base_dir }}/devstack/openrc"
2
+openrc_user: admin
3
+openrc_project: admin
4
+openrc_enable_export: false
0 5
new file mode 100644
... ...
@@ -0,0 +1,14 @@
0
+- when: openrc_enable_export
1
+  block:
2
+    - name: Extract the OS_ environment variables
3
+      shell:
4
+        cmd: |
5
+          source {{ openrc_file }} {{ openrc_user }} {{ openrc_project }} &>/dev/null
6
+          env | awk -F= 'BEGIN {print "---" } /^OS_/ { print "  "$1": \""$2"\""} '
7
+      args:
8
+        executable: "/bin/bash"
9
+      register: env_os
10
+
11
+    - name: Save the OS_ environment variables as a fact
12
+      set_fact:
13
+        os_env_vars: "{{ env_os.stdout|from_yaml }}"