openstack-ansible-os_octavia/tasks/octavia_amp_image.yml
Jesse Pretorius 33a709485c Execute image setup against octavia_service_setup_host
In order to reduce the packages required to pip install on to the hosts,
we use service delegation to octavia_service_setup_host so that instead
of installing software on the target host, and putting credentials on
every target host, we isolate the software and credentials to a single
host.

In this patch we remove the variable 'octavia_image_downloader' and replace
it with just using the 'octavia_service_setup_host' instead. We also need
to add the variable 'octavia_amp_image_path_owner' which is set to the user
running the playbook by default, so that the image can be downloaded to the
deployment host successfully.

There are any other tasks in the role which need updating before we can
eliminate the octavia_requires_pip_packages, but for the sake of keeping
the patch smaller and easier to review they will be done in follow up
patches.

Change-Id: I438cdf695abe223a9fcf7ead796fe2eef41845b7
2018-08-02 09:05:07 +01:00

82 lines
2.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: Get current image id
os_image_facts:
cloud: default
region_name: "{{ octavia_service_region }}"
image: amphora-x64-haproxy
endpoint_type: admin
verify: "{{ not keystone_service_adminuri_insecure }}"
when:
- octavia_download_result | changed
# 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
when:
- octavia_download_result | changed
- name: Delete old image from glance
os_image:
cloud: default
state: absent
region_name: "{{ octavia_service_region }}"
id: "{{ openstack.id }}"
endpoint_type: admin
verify: "{{ not keystone_service_adminuri_insecure }}"
when:
- openstack is defined # result from os_image_facts