Properly match the LXC index item to download

Currently the match will return two results if the
variant to download is 'default' and the index
contains both 'default' and 'default-beta.1'. The
download task then downloads them both and the last
one wins.

This patch corrects the matching mechanism to ensure
that the match is properly delimited to prevent
improper matches.

This patch also ensures that only one download is done
if there are multiple matches. The list of results is
reverse sorted so that the most recent result is used.

Change-Id: I1086d41bd483d91d8d037a3ba8db4f92e738536e
This commit is contained in:
Jesse Pretorius 2018-01-23 17:08:02 +00:00
parent 4b76998744
commit 45bee5806a
4 changed files with 14 additions and 14 deletions

View File

@ -46,11 +46,9 @@
--dir=/tmp
--out=meta.tar.xz
--check-certificate={{ (lxc_hosts_validate_certs | bool) | lower }}
{% for server in lxc_image_cache_server_mirrors %}{{ server }}/{{ item.split(';')[-1] }}/meta.tar.xz {% endfor %}
{% for server in lxc_image_cache_server_mirrors %}{{ server }}/{{ lxc_images[0].split(';')[-1] }}/meta.tar.xz {% endfor %}
args:
warn: no
with_items:
- "{{ lxc_images }}"
tags:
- skip_ansible_lint
- always

View File

@ -33,12 +33,10 @@
- name: Ensure image has been pre-staged
async_status:
jid: "{{ item.ansible_job_id }}"
jid: "{{ prestage_image.ansible_job_id }}"
register: job_result
until: job_result.finished
retries: 60
with_items:
- "{{ prestage_image.results }}"
- name: Retrieve base image
command: >-

View File

@ -127,12 +127,10 @@
- name: Ensure image has been pre-staged
async_status:
jid: "{{ item.ansible_job_id }}"
jid: "{{ prestage_image.ansible_job_id }}"
register: job_result
until: job_result.finished
retries: 60
with_items:
- "{{ prestage_image.results }}"
- name: Place container rootfs
unarchive:

View File

@ -16,7 +16,7 @@
- name: Set LXC cache path fact
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_index_item: "{{ lxc_cache_map.distro }};{{ lxc_cache_map.release }};{{ lxc_cache_map.arch }};{{ lxc_cache_default_variant }}"
cache_index_item: "{{ lxc_cache_map.distro }};{{ lxc_cache_map.release }};{{ lxc_cache_map.arch }};{{ lxc_cache_default_variant }};"
cache_time: "{{ ansible_date_time.epoch }}"
tags:
- always
@ -44,6 +44,11 @@
tags:
- always
# Example index lines:
# ubuntu;xenial;amd64;default;20180123_08:05;/images/ubuntu/xenial/amd64/default/20180123_08:05/
# As there may be multiple images, and they use a timestamp, we can sort
# the resulting list in reverse order and use the first item in the list
# as it will be the latest available.
- name: Set image index fact
set_fact:
lxc_images: >
@ -53,8 +58,11 @@
{%- set _ = images.append(image) %}
{%- endif %}
{%- endfor %}
{{- images -}}
{{- images | sort(reverse=True) -}}
# We only want to download a single image, rather than downloading
# each of them in turn and they overwrite each other as they all
# download to the same file name and path.
- name: Pre-stage the LXC image on the system
shell: >
aria2c
@ -63,15 +71,13 @@
--dir=/tmp
--out=rootfs.tar.xz
--check-certificate={{ (lxc_hosts_validate_certs | bool) | lower }}
{% for server in lxc_image_cache_server_mirrors %}{{ server }}{{ item.split(';')[-1] }}rootfs.tar.xz {% endfor %}
{% for server in lxc_image_cache_server_mirrors %}{{ server }}{{ lxc_images[0].split(';')[-1] }}rootfs.tar.xz {% endfor %}
> /var/log/aria2c-image-prestage.log 2>&1
args:
warn: no
register: prestage_image
async: 300
poll: 0
with_items:
- "{{ lxc_images }}"
tags:
- skip_ansible_lint
- always