kayobe/ansible/roles/swift-block-devices/tasks/main.yml
Mark Goddard f639ad0b35 Use ansible_facts to reference facts
By default, Ansible injects a variable for every fact, prefixed with
ansible_. This can result in a large number of variables for each host,
which at scale can incur a performance penalty. Ansible provides a
configuration option [0] that can be set to False to prevent this
injection of facts. In this case, facts should be referenced via
ansible_facts.<fact>.

This change updates all references to Ansible facts within Kayobe
from using individual fact variables to using the items in the
ansible_facts dictionary. This allows users to disable fact variable
injection in their Ansible configuration, which may provide some
performance improvement.

This change disables fact variable injection in the ansible
configuration used in CI, to catch any attempts to use the injected
variables.

[0] https://docs.ansible.com/ansible/latest/reference_appendices/config.html#inject-facts-as-vars

Story: 2007993
Task: 42464
Depends-On: https://review.opendev.org/c/openstack/kolla-ansible/+/791276

Change-Id: I14db53ed6e57d37bbd28dd5819e432e3fe6628b2
2021-08-21 09:57:29 +02:00

74 lines
2.2 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
cache_valid_time: "{{ apt_cache_valid_time if ansible_facts.os_family == 'Debian' else omit }}"
update_cache: "{{ True if ansible_facts.os_family == 'Debian' else omit }}"
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) }}"