--- # Copyright 2021 City Network International AB # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - name: Setup the guest image delegate_to: "{{ trove_service_setup_host }}" vars: ansible_python_interpreter: "{{ trove_service_setup_host_python_interpreter }}" block: - name: Create image download directory file: path: "{{ trove_image_local_path }}" state: directory mode: "0750" owner: "{{ trove_image_path_owner }}" when: - trove_guestagent_images | length > 0 - name: Download image from artefact server get_url: url: "{{ item.file }}" dest: "{{ trove_image_local_path }}/{{ item.file | basename }}" checksum: "{{ item.checksum | default(omit) }}" mode: "0644" retries: 5 delay: 10 register: trove_download_images until: trove_download_images is success when: item.file | regex_search('^(http|https|ftp)://') is truthy(convert_bool=True) with_items: "{{ trove_guestagent_images }}" - name: Replace existing image with new one when: - trove_download_images is changed block: - name: Get current image id openstack.cloud.image_info: cloud: "{{ item.cloud | default('default') }}" region_name: "{{ trove_service_region }}" image: "{{ item.name }}" interface: "{{ item.interface | default('admin') }}" verify: "{{ not keystone_service_adminuri_insecure }}" register: get_image_info until: get_image_info is success retries: 5 delay: 10 with_items: "{{ trove_download_images['results'] | selectattr('changed') | map(attribute='item') }}" # This uses command since os_image doesn't support tags. # TODO(odyssey4me): # Add tag capability to os_image module and replace this. - name: Upload new image to glance # noqa: no-changed-when jinja[spacing] command: >- openstack image create --os-cloud {{ item.cloud | default('default') }} --os-interface {{ item.interface | default('admin') }} --file {{ trove_image_local_path }}/{{ item.file | basename }} --disk-format {{ item.disk_format | default('qcow2') }} --container-format {{ item.image_format | default('bare') }} {% if item.tags | length > 0%}--tag {{ item.tags | join(' --tag ') }}{% endif %} {{ (item.public | default(False)) | ternary('--public', '--private') }} --project service {{ item.name }} with_items: "{{ trove_download_images['results'] | selectattr('changed') | map(attribute='item') }}" - name: Delete old image from glance openstack.cloud.image: cloud: "{{ item.cloud | default('default') }}" region_name: "{{ trove_service_region }}" state: absent name: "{{ item.id }}" interface: admin verify: "{{ not keystone_service_adminuri_insecure }}" register: remove_old_image until: remove_old_image is success retries: 5 delay: 10 with_items: "{{ get_image_info['results'] | selectattr('openstack_image') | map(attribute='openstack_image') }}"