Initial commit
[ta/infra-ansible.git] / roles / bootstrap-host / tasks / prepare_data_disk.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
17 # Only execute the disk partitioning process if a partition labeled
18 #  'openstack-data{1,2}' is not present and that partition is not
19 #  formatted as ext4. This is an attempt to achieve idempotency just
20 #  in case these tasks are executed multiple times.
21 - name: Determine whether partitions labeled openstack-data{1,2} are present
22   shell: |
23     parted --script -l -m | egrep -q ':ext4:openstack-data[12]:;$'
24   register: data_disk_partitions
25   changed_when: false
26   failed_when: false
27   tags:
28     - check-data-disk-partitions
29
30 - name: Dismount and remove fstab entries for anything on the data disk device
31   mount:
32     name: "{{ item.mount }}"
33     src: "{{ item.device }}"
34     fstype: ext4
35     state: absent
36   when:
37     - data_disk_partitions.rc == 1 or bootstrap_host_data_disk_device_force | bool
38     - item.device | search(bootstrap_host_data_disk_device)
39   with_items:
40     - "{{ ansible_mounts }}"
41
42 - name: Partition the whole data disk for our usage
43   command: "{{ item }}"
44   when: data_disk_partitions.rc == 1 or bootstrap_host_data_disk_device_force | bool
45   with_items:
46     - "parted --script /dev/{{ bootstrap_host_data_disk_device | regex_replace('!','/') }} mklabel gpt"
47     - "parted --align optimal --script /dev/{{ bootstrap_host_data_disk_device | regex_replace('!','/') }} mkpart openstack-data1 ext4 0% 40%"
48     - "parted --align optimal --script /dev/{{ bootstrap_host_data_disk_device | regex_replace('!','/') }} mkpart openstack-data2 ext4 40% 100%"
49   tags:
50     - create-data-disk-partitions
51
52 - name: Format the partitions
53   filesystem:
54     fstype: ext4
55     dev: "{{ item }}"
56   when: data_disk_partitions.rc == 1 or bootstrap_host_data_disk_device_force | bool
57   with_items:
58     - "/dev/{{ bootstrap_host_data_disk_device | regex_replace('!(.*)$','/\\1p') }}1"
59     - "/dev/{{ bootstrap_host_data_disk_device | regex_replace('!(.*)$','/\\1p') }}2"
60   tags:
61     - format-data-partitions
62
63 - name: Create the mount points, fstab entries and mount the file systems
64   mount:
65     name: "{{ item.mount_point }}"
66     src: "{{ item.device }}"
67     fstype: ext4
68     state: mounted
69   with_items:
70     - { mount_point: /openstack, device: "/dev/{{ bootstrap_host_data_disk_device | regex_replace('!(.*)$','/\\1p') }}1"}
71     - { mount_point: /var/lib/lxc, device: "/dev/{{ bootstrap_host_data_disk_device | regex_replace('!(.*)$','/\\1p') }}2"}
72   tags:
73     - mount-data-partitions