08f1a28085
The octavia_amp_image.yml playbook is not idempotent because it is missing some conditional logic and uses an incorrect result variable name for the `os_image_facts` module (albeit following the module documentation). This change also updates the use of the `id` key to the required `name` key in the `os_image` module. Also, the fact get and image deletion need to be done by the service account, not the cloud admin account. Finally, these tasks all have the same conditional, so we put them all into a block. Change-Id: I52e111fffe9a60c879c967c94a895ae272d98fcd
102 lines
3.8 KiB
YAML
102 lines
3.8 KiB
YAML
---
|
|
# Copyright 2018, Rackspace US, Inc.
|
|
#
|
|
# 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.
|
|
|
|
# We set the python interpreter to the ansible runtime venv if
|
|
# the delegation is to localhost so that we get access to the
|
|
# appropriate python libraries in that venv. If the delegation
|
|
# is to another host, we assume that it is accessible by the
|
|
# system python instead.
|
|
- name: Setup the amphora image
|
|
delegate_to: "{{ octavia_service_setup_host }}"
|
|
vars:
|
|
ansible_python_interpreter: >-
|
|
{{ (octavia_service_setup_host == 'localhost') | ternary(ansible_playbook_python, ansible_python['executable']) }}
|
|
block:
|
|
- name: Create image download directory
|
|
file:
|
|
path: "{{ octavia_amp_image_path }}"
|
|
state: directory
|
|
mode: "0750"
|
|
owner: "{{ octavia_amp_image_path_owner }}"
|
|
when:
|
|
- octavia_download_artefact | bool
|
|
|
|
- name: Download image from artefact server
|
|
get_url:
|
|
url: "{{ octavia_artefact_url }}"
|
|
dest: "{{ octavia_amp_image_path }}"
|
|
retries: 10
|
|
delay: 10
|
|
register: octavia_download_result
|
|
when:
|
|
- octavia_download_artefact | bool
|
|
|
|
- name: Replace existing image with new one
|
|
when:
|
|
- octavia_download_result | changed
|
|
block:
|
|
- name: Get current image id
|
|
os_image_facts:
|
|
auth:
|
|
auth_url: "{{ keystone_service_adminurl }}"
|
|
username: "{{ octavia_service_user_name }}"
|
|
password: "{{ octavia_service_password }}"
|
|
project_name: "{{ octavia_service_project_name }}"
|
|
user_domain_name: "{{ octavia_service_user_domain_id }}"
|
|
project_domain_name: "{{ octavia_service_project_domain_id }}"
|
|
region_name: "{{ octavia_service_region }}"
|
|
image: amphora-x64-haproxy
|
|
interface: admin
|
|
verify: "{{ not keystone_service_adminuri_insecure }}"
|
|
register: get_image_facts
|
|
until: get_image_facts is success
|
|
retries: 5
|
|
delay: 10
|
|
|
|
# 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
|
|
command: >-
|
|
openstack image create
|
|
--os-cloud default
|
|
--file {{ octavia_download_result.dest }}
|
|
--disk-format qcow2
|
|
--tag {{ octavia_glance_image_tag }}
|
|
--private
|
|
--project service
|
|
amphora-x64-haproxy
|
|
|
|
- name: Delete old image from glance
|
|
os_image:
|
|
auth:
|
|
auth_url: "{{ keystone_service_adminurl }}"
|
|
username: "{{ octavia_service_user_name }}"
|
|
password: "{{ octavia_service_password }}"
|
|
project_name: "{{ octavia_service_project_name }}"
|
|
user_domain_name: "{{ octavia_service_user_domain_id }}"
|
|
project_domain_name: "{{ octavia_service_project_domain_id }}"
|
|
state: absent
|
|
region_name: "{{ octavia_service_region }}"
|
|
name: "{{ openstack_image.id }}"
|
|
interface: admin
|
|
verify: "{{ not keystone_service_adminuri_insecure }}"
|
|
register: remove_old_image
|
|
until: remove_old_image is success
|
|
retries: 5
|
|
delay: 10
|
|
when:
|
|
- openstack_image.id is defined
|