---
- name: Download snapshots of virtual machines
  hosts: "{{ (_run_condition | bool) | ternary('hypervisor', 'none') }}"
  gather_facts: yes
  any_errors_fatal: true
  tasks:
    - name: Get the manifest file
      uri:
        url: "{{ provision.virsh.snapshot.download.url }}"
        return_content: yes
      register: _manifest_file

    - name: Register manifest file content as a fact
      set_fact:
        _manifest_content: "{{ _manifest_file.content | from_json }}"

    - name: Download the files referenced in the manifest
      get_url:
        url: "{{ provision.virsh.snapshot.download.url | regex_replace('/[^/]*$', '') }}/{{ item.path | basename }}"
        dest: "{{ provision.virsh.snapshot.path }}/{{ item.path | basename }}"
        checksum: "sha1:{{ item.checksum }}"
      loop: "{{ _manifest_content.files }}"
      loop_control:
        label: "{{ item.path | basename }}"
      register: _download_result
      retries: 5
      delay: 10
      until: _download_result is success

---
- name: Download snapshots of virtual machines
  hosts: "{{ (_run_condition | bool) | ternary('hypervisor', 'none') }}"
  gather_facts: yes
  any_errors_fatal: true
  tasks:
    - name: Get the manifest file
      uri:
        url: "{{ provision.virsh.snapshot.download.url }}"
        return_content: yes
      register: _manifest_file

    - name: Save the manifest file
      copy:
        content: "{{ _manifest_file.content | from_json | to_nice_json }}"
        dest: "{{ provision.virsh.snapshot.path }}/manifest.json"
        force: yes

    - name: Register manifest file content as a fact
      set_fact:
        _manifest_content: "{{ _manifest_file.content | from_json }}"

    - name: Download the files referenced in the manifest
      get_url:
        url: "{{ provision.virsh.snapshot.download.url | regex_replace('/[^/]*$', '') }}/{{ item.path | basename }}"
        dest: "{{ provision.virsh.snapshot.path }}/{{ item.path | basename }}"
        checksum: "sha1:{{ item.checksum }}"
      loop: "{{ _manifest_content.files }}"
      loop_control:
        label: "{{ item.path | basename }}"
      register: _download_result
      retries: 5
      delay: 10
      until: _download_result is success

Save the image set manifest when downloading
[virsh] Save the image set manifest when downloading

The download sequence uses the downloaded manifest to save
the image set, but the image set cannot be imported because
the manifest itself is not saved. This patch fixes that.

Change-Id: Ic73e2935b51792bb370deb757a880d636b477875
