MNAIO: Use images subdirectory for VM images
Instead of putting the images in the root of the disk, we use a subdirectory. This prevents silly mistakes from happening. Change-Id: I19d22b7e72de88736db410a771ec22664c641c94
This commit is contained in:
parent
595c2f6cea
commit
5ce798b360
@ -58,7 +58,7 @@
|
||||
|
||||
- name: Delete VM Disk Image
|
||||
file:
|
||||
path: "{{ _virt_pools.pools.default.path | default('/data') }}/{{ hostvars[item]['server_hostname'] }}.img"
|
||||
path: "{{ _virt_pools.pools.default.path | default('/data/images') }}/{{ hostvars[item]['server_hostname'] }}.img"
|
||||
state: absent
|
||||
when:
|
||||
- hostvars[item]['server_vm'] | default(false) | bool
|
||||
@ -89,7 +89,7 @@
|
||||
block:
|
||||
- name: Find existing base image files
|
||||
find:
|
||||
paths: "{{ _virt_pools.pools.default.path | default('/data') }}"
|
||||
paths: "{{ _virt_pools.pools.default.path | default('/data/images') }}"
|
||||
patterns: '*-base.img'
|
||||
register: _base_images
|
||||
|
||||
@ -112,9 +112,9 @@
|
||||
qemu-img create
|
||||
-f qcow2
|
||||
{% if vm_use_snapshot | bool %}
|
||||
-b {{ _virt_pools.pools.default.path | default('/data') }}/{{ hostvars[item]['server_hostname'] }}-base.img
|
||||
-b {{ _virt_pools.pools.default.path | default('/data/images') }}/{{ hostvars[item]['server_hostname'] }}-base.img
|
||||
{% endif %}
|
||||
{{ _virt_pools.pools.default.path | default('/data') }}/{{ hostvars[item]['server_hostname'] }}.img
|
||||
{{ _virt_pools.pools.default.path | default('/data/images') }}/{{ hostvars[item]['server_hostname'] }}.img
|
||||
{{ default_vm_storage }}m
|
||||
when:
|
||||
- hostvars[item]['server_vm'] | default(false) | bool
|
||||
@ -133,7 +133,7 @@
|
||||
command: define
|
||||
xml: >-
|
||||
{%- if (vm_use_snapshot | default(False)) | bool %}
|
||||
{{ lookup('file', _virt_pools.pools.default.path | default('/data') ~ '/' ~ hostvars[item]['server_hostname'] ~ '.xml') }}
|
||||
{{ lookup('file', _virt_pools.pools.default.path | default('/data/images') ~ '/' ~ hostvars[item]['server_hostname'] ~ '.xml') }}
|
||||
{%- else %}
|
||||
{{ lookup('template', 'kvm/kvm-vm.xml.j2') }}
|
||||
{%- endif %}
|
||||
|
@ -41,7 +41,7 @@
|
||||
{% elif default_vm_disk_mode == "file" %}
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2' cache='none' io='native'/>
|
||||
<source file='{{ _virt_pools.pools.default.path | default('/data') }}/{{ hostvars[item]["server_hostname"] }}.img'/>
|
||||
<source file='{{ _virt_pools.pools.default.path | default('/data/images') }}/{{ hostvars[item]["server_hostname"] }}.img'/>
|
||||
{% endif %}
|
||||
<target dev='vda' bus='virtio'/>
|
||||
<address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
|
||||
|
@ -58,7 +58,7 @@
|
||||
fi
|
||||
args:
|
||||
executable: /bin/bash
|
||||
chdir: "{{ _virt_pools.pools.default.path | default('/data') }}"
|
||||
chdir: "{{ _virt_pools.pools.default.path | default('/data/images') }}"
|
||||
when:
|
||||
- hostvars[item]['server_vm'] | default(false) | bool
|
||||
with_items: "{{ groups['pxe_servers'] }}"
|
||||
@ -69,7 +69,7 @@
|
||||
- name: Save VM definition
|
||||
copy:
|
||||
src: "/etc/libvirt/qemu/{{ hostvars[item]['server_hostname'] }}.xml"
|
||||
dest: "{{ _virt_pools.pools.default.path | default('/data') }}/"
|
||||
dest: "{{ _virt_pools.pools.default.path | default('/data/images') }}/"
|
||||
remote_src: yes
|
||||
when:
|
||||
- hostvars[item]['server_vm'] | default(false) | bool
|
||||
@ -86,12 +86,12 @@
|
||||
shell: "pip --disable-pip-version-check freeze > pip-requirements.txt"
|
||||
args:
|
||||
executable: /bin/bash
|
||||
chdir: "{{ _virt_pools.pools.default.path | default('/data') }}"
|
||||
chdir: "{{ _virt_pools.pools.default.path | default('/data/images') }}"
|
||||
changed_when: false
|
||||
|
||||
- name: Find all the files for the manifest
|
||||
find:
|
||||
paths: "{{ _virt_pools.pools.default.path | default('/data') }}"
|
||||
paths: "{{ _virt_pools.pools.default.path | default('/data/images') }}"
|
||||
patterns:
|
||||
- "*-base.img"
|
||||
- "*.xml"
|
||||
@ -107,4 +107,4 @@
|
||||
- name: Write out the manifest file
|
||||
copy:
|
||||
content: "{{ _manifest_content | to_nice_json }}"
|
||||
dest: "{{ _virt_pools.pools.default.path | default('/data') }}/manifest.json"
|
||||
dest: "{{ _virt_pools.pools.default.path | default('/data/images') }}/manifest.json"
|
||||
|
@ -363,6 +363,14 @@
|
||||
state: mounted
|
||||
fstype: ext4
|
||||
|
||||
- name: Create the images directory
|
||||
file:
|
||||
path: /data/images
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
state: directory
|
||||
|
||||
- name: Define the default virt storage pool
|
||||
virt_pool:
|
||||
name: default
|
||||
@ -371,7 +379,7 @@
|
||||
<pool type='dir'>
|
||||
<name>default</name>
|
||||
<target>
|
||||
<path>/data</path>
|
||||
<path>/data/images</path>
|
||||
<permissions>
|
||||
<mode>0755</mode>
|
||||
<owner>0</owner>
|
||||
|
Loading…
x
Reference in New Issue
Block a user