Initial commit
[ta/infra-ansible.git] / roles / bootstrap-host / tasks / prepare_loopback_cinder.yml
1 ---
2 # Copyright 2015, Rackspace US, Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 - name: Create sparse Cinder file
17   command: "truncate -s {{ bootstrap_host_loopback_cinder_size }}G /openstack/cinder.img"
18   args:
19     creates: /openstack/cinder.img
20   register: cinder_create
21   tags:
22     - cinder-file-create
23
24 - name: Get a loopback device for cinder file
25   command: losetup -f
26   when: cinder_create | changed
27   register: cinder_losetup
28   tags:
29     - cinder-device-get
30
31 - name: Create the loopback device
32   command: "losetup {{ cinder_losetup.stdout }} /openstack/cinder.img"
33   when: cinder_create | changed
34   tags:
35     - cinder-device-create
36
37 - name: Ensure that rc.local exists
38   file:
39     path: "{{ rc_local }}"
40     state: touch
41     mode: "u+x"
42   tags:
43     - cinder-rc-file
44
45 # As the cinder loopback is an LVM VG, it needs to be mounted differently
46 #  to the other loopback files. It requires the use of rc.local to attach
47 #  the loopback device on boot so that the VG becomes available immediately
48 #  after the boot process completes.
49 - name: Create loopback devices at boot time
50   lineinfile:
51     dest:  "{{ rc_local }}"
52     line: "losetup $(losetup -f) /openstack/cinder.img"
53     insertbefore: "{{ rc_local_insert_before }}"
54   tags:
55     - cinder-rc-config
56
57 - name: Make LVM physical volume on the cinder device
58   command: "{{ item }}"
59   when: cinder_create | changed
60   with_items:
61     - "pvcreate {{ cinder_losetup.stdout }}"
62     - "pvscan"
63   tags:
64     - cinder-lvm-pv
65
66 - name: Add cinder-volumes volume group
67   lvg:
68     vg: cinder-volumes
69     pvs: "{{ cinder_losetup.stdout }}"
70   when: cinder_create | changed
71   tags:
72     - cinder-lvm-vg