From f5d178cb202c09af7d28ee4a434d9aa85649c5ef Mon Sep 17 00:00:00 2001
From: Chris Hines <chris.hines@monash.edu>
Date: Wed, 13 Jul 2016 04:38:24 +0000
Subject: [PATCH] allow us to make a filesystem on an ephemeral disk as well as
 using a cinder volume supplied with ansible metadata

---
 roles/make_filesystems/tasks/main.yml | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/roles/make_filesystems/tasks/main.yml b/roles/make_filesystems/tasks/main.yml
index 95afe48a..1075e7be 100644
--- a/roles/make_filesystems/tasks/main.yml
+++ b/roles/make_filesystems/tasks/main.yml
@@ -1,13 +1,35 @@
 ---
+- name: set cinder
+  set_fact: cinder=True
+  when: '"ansible_host_volumes" in hostvars[inventory_hostname]'
+
+- name: set ephemeral
+  set_fact: cinder=False
+  when: '"ansible_host_volumes" not in hostvars[inventory_hostname]'
+
 - name: format volumes
   filesystem: fstype={{ item.fstype }} dev={{ hostvars[inventory_hostname]['ansible_host_volumes'][item.name]['dev'] }}
-  with_items: volumes
+  with_items: "{{ volumes }}"
   sudo: true
+  when: cinder
 
 - name: format volumes
   mount: name={{ item.mntpt }} fstype={{ item.fstype }} src={{ hostvars[inventory_hostname]['ansible_host_volumes'][item.name]['dev'] }} state=mounted
-  with_items: volumes
+  with_items: "{{ volumes }}"
+  sudo: true
+  when: cinder
+
+- name: format volumes
+  filesystem: fstype={{ item.fstype }} dev={{ item.name }}
+  with_items: "{{ volumes }}"
+  sudo: true
+  when: not cinder
+
+- name: format volumes
+  mount: name={{ item.mntpt }} fstype={{ item.fstype }} src={{ item.name }} state=mounted
+  with_items: "{{ volumes }}"
   sudo: true
+  when: not cinder
 
 - name: symlink volumes
   file: force=yes state=link src="{{ item.mntpt }}" path="{{ item.linkto }}"
-- 
GitLab