b9f045401c
The code in this playbook assumes that the path to a partition is just the partition number appended to the disk path. However when working with NVMe disks, the partition will actually be "pN" where N is the partition number and p is the literal character. To attempt to be agnostic use lsblk to show all the partitions on the disk, since it was just reformatted and only has the partitions this playbook creates. This is then stored in a new temporary fact that can be used throughout the rest of the playbook. Change-Id: I661696c275fbc2e91d049303f5498ff8d401fc83
179 lines
6.0 KiB
YAML
179 lines
6.0 KiB
YAML
---
|
|
# 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: |
|
|
set -o pipefail;
|
|
parted --script -l -m | egrep -q ':{{ bootstrap_host_data_disk_fs_type }}:openstack-data[12]:;$'
|
|
args:
|
|
executable: /bin/bash
|
|
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_facts['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: Determine partition names
|
|
command: "lsblk /dev/{{ _bootstrap_host_data_disk_device }} -o NAME --noheadings --list"
|
|
register: data_disk_partitions
|
|
when:
|
|
- bootstrap_host_data_disk_device_force | bool
|
|
changed_when: false
|
|
tags:
|
|
- create-data-disk-partitions
|
|
|
|
- name: Set bootstrap host data disk partitions fact
|
|
set_fact:
|
|
_bootstrap_host_data_partition_devices: "{{ data_disk_partitions.stdout_lines[1:] | list }}"
|
|
when:
|
|
- bootstrap_host_data_disk_device_force | bool
|
|
|
|
- name: Format the partition 1
|
|
filesystem:
|
|
fstype: "{{ bootstrap_host_data_disk_fs_type }}"
|
|
dev: "/dev/{{ _bootstrap_host_data_partition_devices[0] }}"
|
|
opts: "{{ bootstrap_host_format_options[bootstrap_host_data_disk_fs_type] | 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_partition_devices[1] }}"
|
|
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_partition_devices[0] }}"
|
|
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_partition_devices[1] }}"
|
|
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: Prepare disk drive as ZFS
|
|
when: _lxc_container_backing_store == 'zfs'
|
|
block:
|
|
- name: Install zfs packages
|
|
package:
|
|
name: "{{ packages_install_zfs }}"
|
|
state: present
|
|
update_cache: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary('yes', omit) }}"
|
|
tags:
|
|
- install-packages
|
|
|
|
- name: Create the ZFS pool
|
|
command: zpool create osa-test-pool "/dev/{{ _bootstrap_host_data_partition_devices[1] }}"
|
|
args:
|
|
creates: /osa-test-pool
|
|
when:
|
|
- bootstrap_host_data_disk_device_force | bool
|
|
|
|
- name: Create the ZFS osa-test-pool/lxc volume
|
|
shell: "(zfs list | grep lxc) || zfs create -o mountpoint=/var/lib/lxc osa-test-pool/lxc"
|
|
when:
|
|
- bootstrap_host_data_disk_device_force | bool
|
|
tags:
|
|
- skip_ansible_lint
|
|
|
|
- name: Prepare disk drive as LVM
|
|
when: _lxc_container_backing_store == 'lvm'
|
|
block:
|
|
- name: Make LVM physical volume on the cinder device
|
|
shell: "pvcreate /dev/{{ _bootstrap_host_data_partition_devices[1] }} && touch /openstack/lxc.pvcreate"
|
|
args:
|
|
creates: "/openstack/lxc.pvcreate"
|
|
tags:
|
|
- skip_ansible_lint
|
|
- data-config
|
|
|
|
- name: Run pvscan
|
|
command: "pvscan"
|
|
changed_when: false
|
|
tags:
|
|
- cinder-lvm-pv
|
|
|
|
- name: Add cinder-volumes volume group
|
|
lvg:
|
|
vg: lxc
|
|
pvs: "/dev/{{ _bootstrap_host_data_partition_devices[1] }}"
|
|
tags:
|
|
- data-config
|