8c0e626bb4aa5a917a6df73e8c37b871192935a0
[genesis.git] / compass / deploy / ansible / roles / cinder-volume / tasks / main.yml
1 ---
2 - name: install cinder-volume and lvm2 packages
3   apt: name={{ item }} state=present force=yes
4   with_items:
5     - cinder-volume
6     - lvm2
7
8 - name: generate cinder volume service list
9   shell: echo {{ item }} >> /opt/service
10   with_items:
11     - cinder-volume
12
13 - name: check if physical device exists
14   stat: path={{ physical_device }}
15   register: st
16
17 - name: repace physical_device if st is false
18   local_action: copy src=loop.yml dest=/tmp/loop.yml
19   when: st.stat.exists == False
20
21 - name: load loop.yml
22   include_vars: /tmp/loop.yml
23   when: st.stat.exists == False
24
25 - name: check if cinder-volumes is mounted
26   shell: ls /mnt
27   register: cindervolumes
28
29 - name: get available partition size
30   shell: df / | awk '$3 ~ /[0-9]+/ { print $4 }'
31   register: partition_size
32
33 - name: if not mounted, mount it
34   shell: dd if=/dev/zero of=/mnt/cinder-volumes
35          bs=1 count=0 seek={{ partition_size.stdout }}
36   when: cindervolumes.stdout != 'cinder-volumes'
37
38 - name: get first lo device
39   shell: ls /dev/loop* | egrep 'loop[0-9]+'|sed -n 1p
40   register: first_lo
41   when: cindervolumes.stdout != 'cinder-volumes'
42
43 - name: do a losetup on /mnt/cinder-volumes
44   shell: losetup {{ first_lo.stdout }} /mnt/cinder-volumes
45   when: cindervolumes.stdout != 'cinder-volumes'
46
47 - name: create physical and group volumes
48   lvg: vg=cinder-volumes pvs={{ physical_device }}
49        vg_options=--force
50
51 - name: upload cinder-volume configuration
52   template: src=cinder.conf dest=/etc/cinder/cinder.conf
53             backup=yes
54   notify:
55      - restart cinder-volume