Merge "MNAIO: Extend image saving to include manifest"
This commit is contained in:
commit
bca923f084
@ -83,7 +83,7 @@
|
||||
- default_vm_disk_mode == "lvm"
|
||||
with_items: "{{ groups['pxe_servers'] }}"
|
||||
|
||||
- name: Setup file-based disk images
|
||||
- name: Setup/clean-up file-based disk images
|
||||
when:
|
||||
- default_vm_disk_mode == "file"
|
||||
block:
|
||||
@ -99,6 +99,14 @@
|
||||
when:
|
||||
- vm_use_snapshot is not defined
|
||||
|
||||
- name: Clean up base image files if they are not being used
|
||||
file:
|
||||
path: "{{ item.path }}"
|
||||
state: absent
|
||||
with_items: "{{ _base_images.files }}"
|
||||
when:
|
||||
- not (vm_use_snapshot | bool)
|
||||
|
||||
- name: Create VM Disk Image
|
||||
command: >-
|
||||
qemu-img create
|
||||
@ -123,7 +131,12 @@
|
||||
virt:
|
||||
name: "{{ hostvars[item]['server_hostname'] }}"
|
||||
command: define
|
||||
xml: "{{ lookup('template', 'kvm/kvm-vm.xml.j2') }}"
|
||||
xml: >-
|
||||
{%- if vm_use_snapshot | bool %}
|
||||
{{ lookup('file', _virt_pools.pools.default.path | default('/data') ~ '/' ~ hostvars[item]['server_hostname'] ~ '.xml') }}
|
||||
{%- else %}
|
||||
{{ lookup('template', 'kvm/kvm-vm.xml.j2') }}
|
||||
{%- endif %}
|
||||
failed_when: false
|
||||
when:
|
||||
- hostvars[item]['server_vm'] | default(false) | bool
|
||||
|
@ -35,6 +35,8 @@
|
||||
virt_pool:
|
||||
command: info
|
||||
register: _virt_pools
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Stop running VMs
|
||||
virt:
|
||||
@ -45,10 +47,63 @@
|
||||
with_items: "{{ groups['pxe_servers'] }}"
|
||||
|
||||
- name: Save VM Disk Image
|
||||
command: >-
|
||||
mv
|
||||
{{ _virt_pools.pools.default.path | default('/data') }}/{{ hostvars[item]['server_hostname'] }}.img
|
||||
{{ _virt_pools.pools.default.path | default('/data') }}/{{ hostvars[item]['server_hostname'] }}-base.img
|
||||
shell: |
|
||||
if [[ -e {{ hostvars[item]['server_hostname'] }}.img ]]; then
|
||||
if [[ -e {{ hostvars[item]['server_hostname'] }}-base.img ]]; then
|
||||
qemu-img commit {{ hostvars[item]['server_hostname'] }}.img
|
||||
else
|
||||
mv {{ hostvars[item]['server_hostname'] }}.img {{ hostvars[item]['server_hostname'] }}-base.img
|
||||
fi
|
||||
exit 2
|
||||
fi
|
||||
args:
|
||||
executable: /bin/bash
|
||||
chdir: "{{ _virt_pools.pools.default.path | default('/data') }}"
|
||||
when:
|
||||
- hostvars[item]['server_vm'] | default(false) | bool
|
||||
with_items: "{{ groups['pxe_servers'] }}"
|
||||
register: _save_disk_image
|
||||
changed_when: _save_disk_image.rc == 2
|
||||
|
||||
- name: Save VM definition
|
||||
copy:
|
||||
src: "/etc/libvirt/qemu/{{ hostvars[item]['server_hostname'] }}.xml"
|
||||
dest: "{{ _virt_pools.pools.default.path | default('/data') }}/"
|
||||
remote_src: yes
|
||||
when:
|
||||
- hostvars[item]['server_vm'] | default(false) | bool
|
||||
with_items: "{{ groups['pxe_servers'] }}"
|
||||
|
||||
- name: Get the current SHA1 for the manifest
|
||||
command: "git rev-parse HEAD"
|
||||
args:
|
||||
chdir: "{{ playbook_dir }}"
|
||||
register: _repo_sha
|
||||
changed_when: false
|
||||
|
||||
- name: Add pip freeze results to the data
|
||||
shell: "pip --disable-pip-version-check freeze > pip-requirements.txt"
|
||||
args:
|
||||
executable: /bin/bash
|
||||
chdir: "{{ _virt_pools.pools.default.path | default('/data') }}"
|
||||
changed_when: false
|
||||
|
||||
- name: Find all the files for the manifest
|
||||
find:
|
||||
paths: "{{ _virt_pools.pools.default.path | default('/data') }}"
|
||||
patterns:
|
||||
- "*-base.img"
|
||||
- "*.xml"
|
||||
- "*.txt"
|
||||
get_checksum: yes
|
||||
register: _manifest_files
|
||||
|
||||
- name: Prepare the manifest file content
|
||||
set_fact:
|
||||
_manifest_content: >-
|
||||
{ 'openstack-ansible-ops_SHA1': '{{ _repo_sha.stdout }}', 'files': {{ _manifest_files.files | json_query('[*].{path: path, checksum: checksum}') | sort(attribute='path') }} }
|
||||
|
||||
- name: Write out the manifest file
|
||||
copy:
|
||||
content: "{{ _manifest_content | to_nice_json }}"
|
||||
dest: "{{ _virt_pools.pools.default.path | default('/data') }}/manifest.json"
|
||||
|
Loading…
x
Reference in New Issue
Block a user