summaryrefslogtreecommitdiff
path: root/src/three-minute-demo/roles
diff options
context:
space:
mode:
Diffstat (limited to 'src/three-minute-demo/roles')
-rw-r--r--src/three-minute-demo/roles/build-image/defaults/main.yaml3
-rw-r--r--src/three-minute-demo/roles/build-image/tasks/main.yaml19
-rw-r--r--src/three-minute-demo/roles/get-cloud-config/tasks/main.yaml6
-rw-r--r--src/three-minute-demo/roles/upload-image/defaults/main.yaml3
-rw-r--r--src/three-minute-demo/roles/upload-image/tasks/main.yaml25
5 files changed, 56 insertions, 0 deletions
diff --git a/src/three-minute-demo/roles/build-image/defaults/main.yaml b/src/three-minute-demo/roles/build-image/defaults/main.yaml
new file mode 100644
index 0000000..b6283b8
--- /dev/null
+++ b/src/three-minute-demo/roles/build-image/defaults/main.yaml
@@ -0,0 +1,3 @@
1distro: debian
2image_formats:
3- qcow2
diff --git a/src/three-minute-demo/roles/build-image/tasks/main.yaml b/src/three-minute-demo/roles/build-image/tasks/main.yaml
new file mode 100644
index 0000000..57be287
--- /dev/null
+++ b/src/three-minute-demo/roles/build-image/tasks/main.yaml
@@ -0,0 +1,19 @@
1- block:
2
3 - name: Check for existing image
4 stat:
5 path: "{{ distro }}.{{ image_formats[0] }}"
6 register: image_file
7
8 - name: Build image
9 command: |
10 disk-image-create -o {{ distro }} -t {{ image_formats | join(',') }} {{ distro }}-minimal simple-init growroot
11 when: not image_file.stat.exists
12
13- rescue:
14
15 - name: Clean up after a build failure
16 file:
17 path: "{{ distro }}.{{ item }}"
18 state: absent
19 with_items: "{{ image_formats }}"
diff --git a/src/three-minute-demo/roles/get-cloud-config/tasks/main.yaml b/src/three-minute-demo/roles/get-cloud-config/tasks/main.yaml
new file mode 100644
index 0000000..e6f5ecd
--- /dev/null
+++ b/src/three-minute-demo/roles/get-cloud-config/tasks/main.yaml
@@ -0,0 +1,6 @@
1- name: Grab OpenStack cloud config from clouds.yaml
2 os_client_config:
3
4- name: Get list of needed image formats
5 set_fact:
6 image_formats: "{{ openstack.clouds|json_query('[*].image_format') | unique }}"
diff --git a/src/three-minute-demo/roles/upload-image/defaults/main.yaml b/src/three-minute-demo/roles/upload-image/defaults/main.yaml
new file mode 100644
index 0000000..b6283b8
--- /dev/null
+++ b/src/three-minute-demo/roles/upload-image/defaults/main.yaml
@@ -0,0 +1,3 @@
1distro: debian
2image_formats:
3- qcow2
diff --git a/src/three-minute-demo/roles/upload-image/tasks/main.yaml b/src/three-minute-demo/roles/upload-image/tasks/main.yaml
new file mode 100644
index 0000000..c14c7eb
--- /dev/null
+++ b/src/three-minute-demo/roles/upload-image/tasks/main.yaml
@@ -0,0 +1,25 @@
1# All three are marked no_log because auth info from clouds.yaml is being
2# extracted and passed around
3
4- name: Check for existing images
5 os_image_facts:
6 cloud: "{{ item.name }}"
7 region_name: "{{ item.region_name }}"
8 image: "three-minute-demo-image"
9 with_items: "{{ openstack.clouds }}"
10 no_log: true
11 register: image_records
12
13- name: Get list of clouds without image
14 set_fact:
15 clouds_without_image: "{{ image_records.results|json_query('[?ansible_facts.openstack_image==null].item') }}"
16 no_log: true
17
18- name: Upload image if it's not there
19 os_image:
20 cloud: "{{ item.name }}"
21 region_name: "{{ item.region_name }}"
22 name: "three-minute-demo-image"
23 filename: "{{ distro }}.{{ item.image_format }}"
24 no_log: true
25 with_items: "{{ clouds_without_image }}"