kayobe/ansible/seed-service-upgrade-prep.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

49 lines
1.8 KiB
YAML

---
- name: Prepare for an upgrade of the seed services
hosts: seed
tasks:
# Bifrost fails if IPA images exist with a different checksum. Move them
# out of the way.
- block:
- name: Find IPA deployment images
find:
path: /var/lib/docker/volumes/bifrost_httpboot/_data
patterns:
# Specify filenames individually to avoid movind previously moved
# images.
- ipa.initramfs
- ipa.initramfs.sha256
- ipa.kernel
- ipa.kernel.sha256
register: find_result
become: true
- name: Set a fact about the current time
set_fact:
ipa_extension: "{{ ansible_facts.date_time.iso8601 }}"
- name: Move old IPA deployment images to make way for new ones
command: mv {{ item.path }} {{ item.path }}.{{ ipa_extension }}
with_items: "{{ find_result.files }}"
loop_control:
label: "{{ item.path }}"
become: true
when: not ipa_build_images | bool
# Bifrost does not perform ironic's online data migrations, which can
# prevent upgrading the database. If the upgrade fails early on, then the
# ironic config file may not exist. On subsequent attempts, this would
# cause the migrations to fail, so skip online migrations if ironic.conf
# doesn't exist.
# TODO: If the ironic config file does exist, we need to check
# the return code, since 2 means that the DB is not compatible
- name: Perform ironic online data migrations
command: >
docker exec bifrost_deploy
bash -c '
if [[ -f /etc/ironic/ironic.conf ]]; then
ironic-dbsync online_data_migrations
fi'
changed_when: true