Use the 'real' name for the LXC image

The Open Build Service repository for the Leap 15.0 LXC image returns
a metalink which causes aria2c to download 2 files. The first is an
empty file (the metalink) and the second is the actual LXC image. The
name of the second file changes frequently.

This change uses the `--on-download-complete` callback of aria2c to
call a helper script which links the expected filename to the actual
filename.

Change-Id: I9a2bc7ded20f772af82956a81a9864c7ee17039c
Signed-off-by: Nicolas Bock <nicolas.bock@suse.com>
This commit is contained in:
Nicolas Bock 2019-04-23 20:30:46 +00:00
parent b5ec1c7eb8
commit ba8a339377
No known key found for this signature in database
GPG Key ID: 9E90013DEF7F5B7B
4 changed files with 21 additions and 12 deletions

View File

@ -45,6 +45,14 @@
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
@ -53,6 +61,8 @@
--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:

View File

@ -63,12 +63,3 @@
enabled: "yes"
tags:
- lxc_hosts-config
- name: Determine latest openSUSE container build information (Leap 15)
# NOTE(hwoarang) The build ID changes all the time so we need to have a hack to determine the latest one
# NOTE(evrardjp) You can still build using your own image by setting lxc_hosts_container_image_url in user_variables.
# NOTE(noonedeadpunk) While suse has static metalink which allows to get to the most recent build,
# aria2c do not save files provided by metalinks under expected names, as --out do not work for them.
shell: |
curl -s {{ _lxc_hosts_container_image_url_base }} | grep -P -o '{{ ansible_architecture }}.*?lxc.*?Build.*?xz' | head -n 1
register: _lxc_opensuse_image_build_info

View File

@ -0,0 +1,10 @@
#!/bin/bash
set -x -e
real_name="$3"
link_name="/tmp/{{ cache_basename }}"
if [[ ${real_name} != ${link_name} ]]; then
ln --symbolic "${real_name}" "${link_name}"
fi

View File

@ -15,9 +15,7 @@
# limitations under the License.
_lxc_hosts_container_image_url_base: "https://download.opensuse.org/repositories/Virtualization:/containers:/images:/openSUSE-Leap-{{ ansible_distribution_version }}/containers/"
# If you want to specify your own image when using SUSE, please override
# in your extra variables lxc_hosts_container_image_url.
_lxc_hosts_container_image_url: "{{ _lxc_hosts_container_image_url_base }}opensuse-leap-image.{{ _lxc_opensuse_image_build_info.stdout }}"
_lxc_hosts_container_image_url: "{{ _lxc_hosts_container_image_url_base }}opensuse-leap-image.x86_64-{{ ansible_distribution_version }}.0.tar.xz"
_lxc_cache_map:
distro: opensuse