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