openstack-ansible-lxc_hosts/tasks/lxc_cache_prestage.yml

88 lines
3.1 KiB
YAML

---
# Copyright 2017, 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.
- name: Set LXC cache fact(s)
set_fact:
cache_path_fact: "{{ lxc_container_cache_path }}/{{ lxc_cache_map.distro }}/{{ lxc_cache_map.release }}/{{ lxc_cache_map.arch }}/{{ lxc_cache_default_variant }}"
cache_time: "{{ ansible_date_time.epoch }}"
- name: Legacy image url fetch
block:
- name: Create legacy image URL fetch
template:
src: "lxc-image-fetch-url.py.j2"
dest: "/usr/local/bin/lxc-image-fetch-url"
owner: "root"
group: "root"
mode: "0755"
- name: Fetch legacy container image url
command: "/usr/local/bin/lxc-image-fetch-url {{ lxc_cache_map.distro }} {{ lxc_cache_map.release }} {{ lxc_cache_map.arch }} {{ lxc_cache_default_variant }}"
register: legacy_image_url
retries: 3
delay: 1
until: legacy_image_url is success
- name: Set LXC cache fact(s) (legacy)
set_fact:
lxc_hosts_container_image_url: "{{ legacy_image_url.stdout.strip() }}"
when:
- lxc_hosts_container_image_download_legacy | bool
- name: Determine lxc_hosts_container_image_url when it is not explicitly set
set_fact:
lxc_hosts_container_image_url: "{{ _lxc_hosts_container_image_url_base ~ '/' ~ lookup('url', _lxc_hosts_container_image_url_base ~ '/' ~ _lxc_hosts_container_image_checksum_file) | regex_findall(_lxc_hosts_container_image_checksum_regexp) | max }}"
register: image_url
retries: 3
delay: 1
until: image_url is success
when:
- lxc_hosts_container_image_url | length == 0
- _lxc_hosts_container_image_url_base is defined
- _lxc_hosts_container_image_checksum_file is defined
- _lxc_hosts_container_image_checksum_regexp is defined
- name: Set LXC cache basename
set_fact:
cache_basename: "{{ lxc_hosts_container_image_url | basename }}"
- name: Create aria2c output script
template:
src: aria2c-download-helper.sh.j2
dest: /usr/local/bin/aria2c-download-helper.sh
owner: "root"
group: "root"
mode: "0755"
- name: Pre-stage the LXC image on the system
shell: >
aria2c
--max-connection-per-server=4
--allow-overwrite=true
--dir=/tmp
--out={{ cache_basename }}
--check-certificate={{ (lxc_hosts_validate_certs | bool) | lower }}
--follow-metalink=mem
--on-download-complete=/usr/local/bin/aria2c-download-helper.sh
{{ lxc_hosts_container_image_url }}
> /var/log/aria2c-image-prestage.log 2>&1
args:
warn: no
register: prestage_image
async: "{{ lxc_cache_prep_timeout | int // 5 }}"
poll: 0
tags:
- skip_ansible_lint