automatically cache undercloud images
with this commit, once an image is fetched successfully and we validate the checksum we save the image using the md5 checksum as the name, and in subsequent runs we use the cached copy rather than fetching it again. this also means that we support arbitrarily named remote images (so you can fetch "undercloud-image-with-extra-sauce.qcow2" and it will work just fine). Change-Id: I1c7b1c4ba110f2cc730c8a694494772dd52ad487
This commit is contained in:
@@ -2,3 +2,5 @@ qemu_executable:
|
||||
Fedora: /usr/bin/qemu-kvm
|
||||
CentOS: /usr/libexec/qemu-kvm
|
||||
'Red Hat Enterprise Linux': /usr/libexec/qemu-kvm
|
||||
|
||||
image_cache_directory: /usr/share/oooq_images/
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
# Fetching the undercloud images can take a long time. This
|
||||
# tasklist caches images in {{ image_cache_directory }} if an image is
|
||||
# (a) downloaded successfully and (b) successfully verifies against
|
||||
# the checksum. Images are cached using the checksum as the filename,
|
||||
# and subsequent playbook runs will use the cached copy rather than
|
||||
# trying to fetch the remote copy.
|
||||
|
||||
- name: ensure image cache directory exists
|
||||
file:
|
||||
path: "{{ image_cache_directory }}"
|
||||
state: directory
|
||||
become: true
|
||||
|
||||
- name: get undercloud image expected checksum
|
||||
command: >
|
||||
curl -sf {{url}}.md5
|
||||
register: undercloud_md5_expected
|
||||
|
||||
- name: check for undercloud image in cache
|
||||
command: >
|
||||
test -f {{undercloud_md5_expected.stdout.split()[0]}}.qcow2
|
||||
args:
|
||||
chdir: "{{ image_cache_directory }}"
|
||||
ignore_errors: true
|
||||
register: image_exists
|
||||
changed_when: false
|
||||
|
||||
- name: get undercloud image
|
||||
command: >
|
||||
curl -sf -C- -o _undercloud.qcow2 {{ url }}
|
||||
args:
|
||||
chdir: "{{ image_cache_directory }}"
|
||||
register: curl_result
|
||||
until: curl_result.rc not in [18, 56]
|
||||
retries: 20
|
||||
delay: 5
|
||||
become: true
|
||||
when: image_exists|failed
|
||||
|
||||
- name: get actual md5 checksum of undercloud image
|
||||
command: >
|
||||
md5sum _undercloud.qcow2
|
||||
args:
|
||||
chdir: "{{ image_cache_directory }}"
|
||||
register: undercloud_md5_actual
|
||||
when: image_exists|failed
|
||||
|
||||
- name: verify undercloud image checksum
|
||||
fail:
|
||||
msg: undercloud image checksum does not match
|
||||
when: >
|
||||
image_exists|failed and (
|
||||
undercloud_md5_expected.stdout.split()[0] !=
|
||||
undercloud_md5_actual.stdout.split()[0])
|
||||
|
||||
- name: cache undercloud image by checksum
|
||||
command: >
|
||||
mv _undercloud.qcow2 {{ undercloud_md5_expected.stdout.split()[0] }}.qcow2
|
||||
args:
|
||||
chdir: "{{ image_cache_directory }}"
|
||||
when: image_exists|failed
|
||||
become: true
|
||||
|
||||
- name: get undercloud image from cache
|
||||
command:
|
||||
cp {{ image_cache_directory }}/{{undercloud_md5_expected.stdout.split()[0]}}.qcow2
|
||||
{{ working_dir }}/undercloud.qcow2
|
||||
become: true
|
||||
become_user: "{{ non_root_user }}"
|
||||
@@ -12,34 +12,7 @@
|
||||
bridges: "{{ networks.bridges }}"
|
||||
register: undercloud_mac_map
|
||||
|
||||
- name: get undercloud appliance image
|
||||
command: >
|
||||
curl -sf -C- -o "{{item.dest}}" "{{item.url}}"
|
||||
args:
|
||||
chdir: "{{ working_dir }}"
|
||||
register: curl_result
|
||||
|
||||
# see https://curl.haxx.se/libcurl/c/libcurl-errors.html
|
||||
# for a list of curl exit codes. we're retrying on
|
||||
# 18 (CURLE_PARTIAL_FILE) and 56 (CURLE_RECV_ERROR).
|
||||
until: curl_result.rc not in [18, 56]
|
||||
retries: 20
|
||||
delay: 5
|
||||
with_items:
|
||||
- url: "{{url}}"
|
||||
dest: undercloud.qcow2
|
||||
- url: "{{url}}.md5"
|
||||
dest: undercloud.qcow2.md5
|
||||
become: true
|
||||
become_user: "{{non_root_user}}"
|
||||
|
||||
- name: verify undercloud appliance image
|
||||
command: >
|
||||
md5sum -c undercloud.qcow2.md5
|
||||
args:
|
||||
chdir: "{{ working_dir }}"
|
||||
become: true
|
||||
become_user: "{{non_root_user}}"
|
||||
- include: fetch_image.yml
|
||||
|
||||
- name: copy instackenv.json to appliance
|
||||
shell: |
|
||||
|
||||
Reference in New Issue
Block a user