
With update of ansible-lint to version >=6.0.0 a lot of new linters were added, that enabled by default. In order to comply with linter rules we're applying changes to the role. With that we also update metdata to reflect current state. Depends-On: https://review.opendev.org/c/openstack/ansible-role-systemd_service/+/888223 Change-Id: Iaab0ad50fd65287094522f77283a0112859d7730
90 lines
3.7 KiB
YAML
90 lines
3.7 KiB
YAML
---
|
|
# 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') }}"
|