Nick Jones 5265993134
Don't assume user's primary group name is the same as username
In certain environments, a user's primary group doesn't necessarily
match that of their username.  This change updates various playbooks to
make use of the `ansible_user_gid` fact instead.

This change also makes ownership explicit by using `ansible_user_uid`
instead of `ansible_user` or `ansible_user_id`, where appropriate.

Change-Id: Ifc2ea7d95ec90e91791ccb10772b15d991379479
Story: 2002770
Task: 22636
2018-07-04 19:56:05 +01:00

98 lines
3.2 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 downloaded
get_url:
url: "{{ item.url }}"
dest: "{{ ipa_images_cache_path }}/{{ item.filename }}"
with_items:
- url: "{{ ipa_images_kernel_url }}"
filename: "{{ ipa_images_kernel_name }}"
- url: "{{ ipa_images_ramdisk_url }}"
filename: "{{ ipa_images_ramdisk_name }}"
when: item.url != None
- name: Compute the MD5 checksum of the Ironic Python Agent (IPA) images
stat:
path: "{{ ipa_images_cache_path }}/{{ item }}"
get_md5: True
get_checksum: False
mime: False
with_items:
- "{{ ipa_images_kernel_name }}"
- "{{ ipa_images_ramdisk_name }}"
register: ipa_images_checksum
- name: Activate the virtualenv
include_role:
name: activate-virtualenv
vars:
activate_virtualenv_path: "{{ ipa_images_venv }}"
# 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 }}"
image: "{{ ipa_images_kernel_name }}"
- name: Set a fact containing the Ironic Python Agent (IPA) kernel image checksum
set_fact:
ipa_images_kernel_checksum: "{{ openstack_image.checksum }}"
when: openstack_image != None
- 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 }}"
image: "{{ ipa_images_ramdisk_name }}"
- name: Set a fact containing the Ironic Python Agent (IPA) ramdisk image checksum
set_fact:
ipa_images_ramdisk_checksum: "{{ openstack_image.checksum }}"
when: openstack_image != None
- name: Ensure Ironic Python Agent (IPA) images are removed from Glance
os_image:
auth_type: "{{ ipa_images_openstack_auth_type }}"
auth: "{{ ipa_images_openstack_auth }}"
name: "{{ item.name }}"
state: absent
with_items:
- name: "{{ ipa_images_kernel_name }}"
checksum: "{{ ipa_images_checksum.results[0].stat.md5 }}"
glance_checksum: "{{ ipa_images_kernel_checksum | default }}"
- name: "{{ ipa_images_ramdisk_name }}"
checksum: "{{ ipa_images_checksum.results[1].stat.md5 }}"
glance_checksum: "{{ ipa_images_ramdisk_checksum | default }}"
when:
- item.glance_checksum != None
- item.checksum != item.glance_checksum
- 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 }}"
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
- name: Deactivate the virtualenv
include_role:
name: deactivate-virtualenv