Files
kayobe/ansible/roles/ipa-images/tasks/main.yml
Mark Goddard ddfd6b6202 Update packages in virtualenvs
Kayobe uses a number of virtual environments on the remote hosts for
python dependencies such as shade, python-openstackclient, docker, etc.
By default these are stored in /opt/kayobe/venvs/. Typically we do not
provide version restrictions when installing these packages, so over the
course of time they may become stale and incompatible.

This change installs the latest version of packages allowed by OpenStack
upper constraints.

It also adds a new variable, 'pip_upper_constraints_file', to set the
upper constraints file. The existing variable
'kolla_upper_constraints_file' now defaults to the value of
'pip_upper_constraints_file'.

Change-Id: I8d2956f95bbc44b5a9e88e7569372048a62f12f5
Story: 2005923
Task: 34193
2019-08-15 11:01:49 +00:00

135 lines
5.1 KiB
YAML

---
- name: Ensure image download directory exists
file:
path: "{{ ipa_images_cache_path }}"
state: directory
owner: "{{ ansible_user_uid }}"
group: "{{ ansible_user_gid }}"
become: True
- name: Ensure Ironic Python Agent (IPA) images are present
vars:
image_download_url: "{{ item.url }}"
image_download_checksum_url: "{{ item.checksum_url }}"
image_download_checksum_algorithm: "{{ item.checksum_algorithm }}"
image_download_dest: "{{ item.dest }}"
include_role:
name: image-download
with_items:
- url: "{{ ipa_images_kernel_url }}"
checksum_url: "{{ ipa_images_kernel_checksum_url }}"
checksum_algorithm: "{{ ipa_images_kernel_checksum_algorithm }}"
dest: "{{ ipa_images_cache_path }}/{{ ipa_images_kernel_name }}"
- url: "{{ ipa_images_ramdisk_url }}"
checksum_url: "{{ ipa_images_ramdisk_checksum_url }}"
checksum_algorithm: "{{ ipa_images_ramdisk_checksum_algorithm }}"
dest: "{{ ipa_images_cache_path }}/{{ ipa_images_ramdisk_name }}"
when: item.url is not none
loop_control:
label: "{{ item.dest }}"
- name: Compute the MD5 checksum of the Ironic Python Agent (IPA) images
stat:
path: "{{ ipa_images_cache_path }}/{{ item }}"
get_checksum: True
checksum_algorithm: md5
mime: False
with_items:
- "{{ ipa_images_kernel_name }}"
- "{{ ipa_images_ramdisk_name }}"
register: ipa_images_checksum
- name: Fail if an image does not exist
fail:
msg: "{{ item.path }} does not exist"
with_items:
- path: "{{ ipa_images_cache_path }}/{{ ipa_images_kernel_name }}"
exists: "{{ ipa_images_checksum.results[0].stat.exists | bool }}"
- path: "{{ ipa_images_cache_path }}/{{ ipa_images_ramdisk_name }}"
exists: "{{ ipa_images_checksum.results[1].stat.exists | bool }}"
when:
- not item.exists
- name: Activate the virtualenv
include_role:
name: activate-virtualenv
vars:
activate_virtualenv_path: "{{ ipa_images_venv }}"
- name: Ensure we have python-ironicclient installed
pip:
name: python-ironicclient
state: latest
virtualenv: "{{ ipa_images_venv }}"
extra_args: "{% if ipa_images_upper_constraints_file %}-c {{ ipa_images_upper_constraints_file }}{% endif %}"
# To support updating the IPA image, we check the MD5 sum of the cached image
# files, and compare with the images in Glance (if there are any).
- name: Gather facts about Ironic Python Agent (IPA) kernel image
os_image_facts:
auth_type: "{{ ipa_images_openstack_auth_type }}"
auth: "{{ ipa_images_openstack_auth }}"
cacert: "{{ ipa_images_openstack_cacert | default(omit, true) }}"
image: "{{ ipa_images_kernel_name }}"
- name: Set a fact containing the Ironic Python Agent (IPA) kernel image
set_fact:
ipa_images_kernel_openstack_image: "{{ openstack_image if openstack_image else {} }}"
- name: Gather facts about Ironic Python Agent (IPA) ramdisk image
os_image_facts:
auth_type: "{{ ipa_images_openstack_auth_type }}"
auth: "{{ ipa_images_openstack_auth }}"
cacert: "{{ ipa_images_openstack_cacert | default(omit, true) }}"
image: "{{ ipa_images_ramdisk_name }}"
- name: Set a fact containing the Ironic Python Agent (IPA) ramdisk image
set_fact:
ipa_images_ramdisk_openstack_image: "{{ openstack_image if openstack_image else {} }}"
# The os_image module will get confused if there are multiple images with the
# same name, so rename the old images. They will still be accessible via UUID.
- name: Ensure old Ironic Python Agent (IPA) images are renamed
command: >
{{ ipa_images_venv }}/bin/openstack image set {{ item.name }} --name {{ item.name }}.{{ extension }}
vars:
extension: "{{ item.created_at | replace(':', '-') }}~"
with_items:
- name: "{{ ipa_images_kernel_name }}"
created_at: "{{ ipa_images_kernel_openstack_image.created_at | default }}"
checksum: "{{ ipa_images_checksum.results[0].stat.checksum }}"
glance_checksum: "{{ ipa_images_kernel_openstack_image.checksum | default }}"
- name: "{{ ipa_images_ramdisk_name }}"
created_at: "{{ ipa_images_ramdisk_openstack_image.created_at | default }}"
checksum: "{{ ipa_images_checksum.results[1].stat.checksum }}"
glance_checksum: "{{ ipa_images_ramdisk_openstack_image.checksum | default }}"
when:
- item.glance_checksum
- item.checksum != item.glance_checksum
environment: "{{ ipa_images_openstack_auth_env }}"
- name: Ensure Ironic Python Agent (IPA) images are registered with Glance
os_image:
auth_type: "{{ ipa_images_openstack_auth_type }}"
auth: "{{ ipa_images_openstack_auth }}"
cacert: "{{ ipa_images_openstack_cacert | default(omit, true) }}"
name: "{{ item.name }}"
container_format: "{{ item.format }}"
disk_format: "{{ item.format }}"
state: present
filename: "{{ ipa_images_cache_path }}/{{ item.name }}"
with_items:
- name: "{{ ipa_images_kernel_name }}"
format: aki
- name: "{{ ipa_images_ramdisk_name }}"
format: ari
register: ipa_images_new_images
- include_tasks: set-driver-info.yml
when: ipa_images_update_ironic_nodes | bool
- name: Deactivate the virtualenv
include_role:
name: deactivate-virtualenv