From 4ac60cf090af9618bd52b4b30cac4ee31b5d5967 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sun, 5 Nov 2017 13:24:37 +1100 Subject: Add ansible playbooks for 3 minute multi-cloud demo --- .../roles/build-image/defaults/main.yaml | 3 +++ .../roles/build-image/tasks/main.yaml | 19 ++++++++++++++++ .../roles/get-cloud-config/tasks/main.yaml | 6 ++++++ .../roles/upload-image/defaults/main.yaml | 3 +++ .../roles/upload-image/tasks/main.yaml | 25 ++++++++++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 src/three-minute-demo/roles/build-image/defaults/main.yaml create mode 100644 src/three-minute-demo/roles/build-image/tasks/main.yaml create mode 100644 src/three-minute-demo/roles/get-cloud-config/tasks/main.yaml create mode 100644 src/three-minute-demo/roles/upload-image/defaults/main.yaml create mode 100644 src/three-minute-demo/roles/upload-image/tasks/main.yaml (limited to 'src/three-minute-demo/roles') 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 @@ +distro: debian +image_formats: +- 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 @@ +- block: + + - name: Check for existing image + stat: + path: "{{ distro }}.{{ image_formats[0] }}" + register: image_file + + - name: Build image + command: | + disk-image-create -o {{ distro }} -t {{ image_formats | join(',') }} {{ distro }}-minimal simple-init growroot + when: not image_file.stat.exists + +- rescue: + + - name: Clean up after a build failure + file: + path: "{{ distro }}.{{ item }}" + state: absent + 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 @@ +- name: Grab OpenStack cloud config from clouds.yaml + os_client_config: + +- name: Get list of needed image formats + set_fact: + 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 @@ +distro: debian +image_formats: +- 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 @@ +# All three are marked no_log because auth info from clouds.yaml is being +# extracted and passed around + +- name: Check for existing images + os_image_facts: + cloud: "{{ item.name }}" + region_name: "{{ item.region_name }}" + image: "three-minute-demo-image" + with_items: "{{ openstack.clouds }}" + no_log: true + register: image_records + +- name: Get list of clouds without image + set_fact: + clouds_without_image: "{{ image_records.results|json_query('[?ansible_facts.openstack_image==null].item') }}" + no_log: true + +- name: Upload image if it's not there + os_image: + cloud: "{{ item.name }}" + region_name: "{{ item.region_name }}" + name: "three-minute-demo-image" + filename: "{{ distro }}.{{ item.image_format }}" + no_log: true + with_items: "{{ clouds_without_image }}" -- cgit v1.2.3