/
prepare_data_disk.yml
154 lines (140 loc) · 5.04 KB
/
prepare_data_disk.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
---
# Copyright 2015, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Only execute the disk partitioning process if a partition labeled
# 'openstack-data{1,2}' is not present and that partition is not
# formatted as ext4. This is an attempt to achieve idempotency just
# in case these tasks are executed multiple times.
- name: Determine whether partitions labeled openstack-data{1,2} are present
shell: |
parted --script -l -m | egrep -q ':{{ bootstrap_host_data_disk_fs_type }}:openstack-data[12]:;$'
register: data_disk_partitions
changed_when: false
failed_when: false
tags:
- check-data-disk-partitions
- name: Set bootstrap host data disk fact
set_fact:
bootstrap_host_data_disk_device_force: true
_bootstrap_host_data_disk_device: "{{ (bootstrap_host_data_disk_device | regex_replace('!','/')).strip() }}"
when:
- data_disk_partitions.rc == 1
- name: Dismount and remove fstab entries for anything on the data disk device
mount:
name: "{{ item.mount }}"
src: "{{ item.device }}"
fstype: "{{ bootstrap_host_data_disk_fs_type }}"
state: absent
when:
- bootstrap_host_data_disk_device_force | bool
- item.device is search(bootstrap_host_data_disk_device)
with_items:
- "{{ ansible_mounts }}"
- name: Partition the whole data disk for our usage
command: "{{ item }}"
when:
- bootstrap_host_data_disk_device_force | bool
with_items:
- "parted --script /dev/{{ _bootstrap_host_data_disk_device }} mklabel gpt"
- "parted --align optimal --script /dev/{{ _bootstrap_host_data_disk_device }} mkpart openstack-data1 {{ bootstrap_host_data_disk_fs_type }} 0% 40%"
- "parted --align optimal --script /dev/{{ _bootstrap_host_data_disk_device }} mkpart openstack-data2 {{ bootstrap_host_data_disk2_fs }} 40% 100%"
tags:
- create-data-disk-partitions
- name: Format the partition 1
filesystem:
fstype: "{{ bootstrap_host_data_disk_fs_type }}"
dev: "/dev/{{ _bootstrap_host_data_disk_device }}1"
opts: "{{ bootstrap_host_format_options['ext4'] | default(omit) }}"
when:
- bootstrap_host_data_disk_device_force | bool
tags:
- format-data-partitions
- name: Format the partition 2
filesystem:
fstype: "{{ bootstrap_host_data_disk2_fs }}"
dev: "/dev/{{ _bootstrap_host_data_disk_device }}2"
opts: "{{ bootstrap_host_format_options[bootstrap_host_data_disk2_fs] | default(omit) }}"
when:
- bootstrap_host_data_disk_device_force | bool
- lxc_container_backing_store != 'lvm'
- lxc_container_backing_store != 'zfs'
tags:
- format-data-partitions
- name: Run the systemd mount role
include_role:
name: systemd_mount
vars:
systemd_mounts:
- what: "/dev/{{ _bootstrap_host_data_disk_device }}1"
where: "/openstack"
type: "{{ bootstrap_host_data_disk_fs_type }}"
options: "{{ bootstrap_host_data_mount_options[bootstrap_host_data_disk_fs_type] }}"
state: 'started'
enabled: true
tags:
- data-config
- name: Run the systemd mount role
include_role:
name: systemd_mount
vars:
systemd_mounts:
- what: "/dev/{{ _bootstrap_host_data_disk_device }}2"
where: "{{ bootstrap_host_data_disk2_path }}"
type: "{{ bootstrap_host_data_disk2_fs }}"
options: "{{ bootstrap_host_data_disk2_fs_mount_options }}"
state: 'started'
enabled: true
when:
- lxc_container_backing_store != 'lvm'
- lxc_container_backing_store != 'zfs'
tags:
- data-config
- name: Create the ZFS pool
command: zpool create pool "/dev/{{ _bootstrap_host_data_disk_device }}2"
args:
creates: /pool
when:
- bootstrap_host_data_disk_device_force | bool
- lxc_container_backing_store == 'zfs'
- name: Create the ZFS pool/lxc volume
shell: "(zfs list | grep lxc) || zfs create -o mountpoint=/var/lib/lxc pool/lxc"
when:
- bootstrap_host_data_disk_device_force | bool
- lxc_container_backing_store == 'zfs'
tags:
- skip_ansible_lint
- name: Make LVM physical volume on the cinder device
shell: "pvcreate /dev/{{ _bootstrap_host_data_disk_device }}2 && touch /openstack/lxc.pvcreate"
args:
creates: "/openstack/lxc.pvcreate"
when:
- lxc_container_backing_store == 'lvm'
tags:
- skip_ansible_lint
- data-config
- name: Run pvscan
command: "pvscan"
changed_when: false
when:
- lxc_container_backing_store == 'lvm'
tags:
- cinder-lvm-pv
- name: Add cinder-volumes volume group
lvg:
vg: lxc
pvs: "/dev/{{ _bootstrap_host_data_disk_device }}2"
when:
- lxc_container_backing_store == 'lvm'
tags:
- data-config