f639ad0b35
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
63 lines
2.2 KiB
YAML
63 lines
2.2 KiB
YAML
---
|
|
# Warning! These tasks can result in lost data. Take care when developing and
|
|
# using them.
|
|
|
|
# Initialisation tasks to be applied on first boot of a system to initalise
|
|
# disks. We search for block devices that are not currently mounted, then wipe
|
|
# any LVM or file system state from them.
|
|
|
|
- name: Ensure LVM2 is installed
|
|
package:
|
|
name: lvm2
|
|
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
|
|
|
|
- name: Check for unmounted block devices
|
|
shell: >
|
|
lsblk -i -o NAME,MOUNTPOINT | awk \
|
|
'/^ *[|`]-/ && NF > 1 { mounts[master_dev] = mounts[master_dev] $2 " " }
|
|
/^(nvme|sd|vd)/ && NF == 1 { master_dev = $1; mounts[master_dev] = "" }
|
|
END { for (dev in mounts) if (mounts[dev] == "") print dev }'
|
|
register: unmounted_devices
|
|
changed_when: False
|
|
|
|
- name: Ensure that all unmounted block devices have LVM state removed
|
|
shell: |
|
|
set -e
|
|
if pvs /dev/{{ item }} >/dev/null 2>&1
|
|
then
|
|
echo "Found PV on /dev/{{ item }}"
|
|
vg=$(pvs --noheadings -o vg_name /dev/{{ item }})
|
|
if [[ -n $vg ]] && [[ $vg != " " ]]
|
|
then
|
|
echo "Found VG $vg on PV /dev/{{ item }}"
|
|
lvs --noheadings -o lv_name $vg | while read lv
|
|
do
|
|
if [[ -n $lv ]] && [[ $lv != " " ]]
|
|
then
|
|
echo "Found LV $lv on VG $vg. Removing"
|
|
lvremove -yf ${vg}/${lv}
|
|
fi
|
|
done
|
|
vgremove -f $vg
|
|
fi
|
|
pvremove -yff /dev/{{ item }}
|
|
fi
|
|
with_items: "{{ unmounted_devices.stdout_lines }}"
|
|
become: True
|
|
|
|
- name: Ensure that all unmounted block devices have filesystems wiped
|
|
command: "wipefs -f /dev/{{ item }}"
|
|
with_items: "{{ unmounted_devices.stdout_lines }}"
|
|
become: True
|
|
# The command can fail in some cases which are valid, so ignore the
|
|
# result.
|
|
failed_when: False
|
|
|
|
- name: Ensure that all unmounted block device headers are zeroed
|
|
command: "dd if=/dev/zero of=/dev/{{ item }} bs=1M count=100"
|
|
with_items: "{{ unmounted_devices.stdout_lines }}"
|
|
become: True
|