kayobe/ansible/roles/swift-block-devices/tasks/main.yml
Mark Goddard c4ffd39478 Switch to generic package module
This makes platform independence easier. There are some cases where we
still use the yum module, where we use yum-specific module parameters.

Also switch use of the state 'installed' to 'present', which is
supported by all the package modules, whereas installed is supported by
the yum module only.

Change-Id: Id1cf845adc7aa6565a7a570569c9a81a478560f0
2019-12-09 10:21:20 +00:00

72 lines
2.1 KiB
YAML

---
- name: Fail if swift_block_devices is not in the expected format
fail:
msg: >-
Device {{ device_index }} in swift_block_devices is in an invalid format.
Items should be a dict, containing at least a 'device' field.
with_items: "{{ swift_block_devices }}"
when: item is not mapping or 'device' not in item
loop_control:
index_var: device_index
- name: Ensure required packages are installed
package:
name:
- parted
- xfsprogs
state: present
become: True
when: swift_block_devices | length > 0
- name: Check the presence of a partition on the Swift block devices
become: True
parted:
device: "{{ item.device }}"
with_items: "{{ swift_block_devices }}"
loop_control:
label: "{{ item.device }}"
register: swift_disk_info
- name: Fail if the Swift block devices have already a partition
fail:
msg: >
The physical disk {{ item.item.device }} already has a partition.
Ensure that each disk in 'swift_block_devices' does not have any
partitions.
with_items: "{{ swift_disk_info.results }}"
when:
- item.partitions | length > 0
- item.partitions.0.name != swift_block_devices_part_label
loop_control:
label: "{{ item.item.device }}"
- name: Ensure partitions exist for Swift block device
become: True
parted:
device: "{{ item.item.device }}"
number: 1
label: gpt
name: "{{ swift_block_devices_part_label }}"
state: present
with_items: "{{ swift_disk_info.results }}"
when: item.partitions | length == 0
loop_control:
label: "{{ item.item.device }}"
- name: Ensure Swift XFS file systems exist
become: true
filesystem:
dev: "{{ partition_name }}"
force: true
fstype: xfs
opts: "-L {{ fs_label }}"
with_items: "{{ swift_disk_info.results }}"
when: item.partitions | length == 0
loop_control:
label: "{{ device }}"
index_var: index
vars:
device: "{{ item.item.device }}"
partition_name: "{{ device }}{% if device.startswith('/dev/loop') %}p{% endif %}1"
fs_label: "{{ item.item.fs_label | default(device | basename) }}"