besseres templating für VMs

This commit is contained in:
Martin Wohlert 2021-06-09 21:07:20 +02:00
parent 30617b19a6
commit 00623c7f0c
5 changed files with 29 additions and 14 deletions

View File

@ -1,6 +1 @@
virt:
host: localhost
image: fedora-34-x64.qcow2
cpus: 2
ram: 2048
hdd: 10g
vm_template: fedora_34

View File

@ -1,16 +1,20 @@
---
- include_vars: vm_templates.yml
- name: test
debug:
msg: "{{ vm_templates[item] }}"
loop: "{{ vm_templates|flatten(1) }}"
- name: fetch images
get_url:
dest: "{{ libvirt.images }}/{{ item.dest }}"
dest: "{{ libvirt.images }}/{{ vm_templates[item].image.filename }}"
group: root
owner: root
mode: u=rw,g=r,o=r
url: "{{ item.url }}"
checksum: "{{ item.checksum }}"
with_items:
- dest: fedora-34-x64.qcow2
checksum: sha1:fc08ad81a893b8253ec3bf6e25273cbb4fc8eafb
url: https://download.fedoraproject.org/pub/fedora/linux/releases/34/Cloud/x86_64/images/Fedora-Cloud-Base-34-1.2.x86_64.qcow2
url: "{{ vm_templates[item].image.url }}"
checksum: "{{ vm_templates[item].image.checksum }}"
loop: "{{ vm_templates|flatten(1) }}"
- name: virt_net "docker" present
virt_net:

View File

@ -4,7 +4,7 @@
- name: create vm storage
delegate_to: "{{ virt.host }}"
copy:
src: "{{ libvirt.images }}/{{ virt.image }}"
src: "{{ libvirt.images }}/{{ virt.image.filename }}"
dest: "{{ libvirt.images }}/{{ inventory_hostname }}.qcow2"
force: no

View File

@ -1,4 +1,6 @@
---
- include_vars: vm_templates.yml
- name: check vm existance
delegate_to: "{{ virt.host }}"
stat:
@ -6,8 +8,12 @@
get_checksum: false
get_attributes: false
get_mime: false
vars:
virt: "{{ vm_templates[vm_template] }}"
register: vmimg
- name: create vm
include_tasks: create_vm.yml
vars:
virt: "{{ vm_templates[vm_template] }}"
when: not vmimg.stat.exists

10
vm_templates.yml Normal file
View File

@ -0,0 +1,10 @@
vm_templates:
fedora_34:
host: localhost
cpus: 1
ram: 1024
hdd: 5g
image:
checksum: sha1:fc08ad81a893b8253ec3bf6e25273cbb4fc8eafb
filename: fedora-34.qcow2
url: https://download.fedoraproject.org/pub/fedora/linux/releases/34/Cloud/x86_64/images/Fedora-Cloud-Base-34-1.2.x86_64.qcow2