besseres templating für VMs
This commit is contained in:
parent
30617b19a6
commit
00623c7f0c
@ -1,6 +1 @@
|
|||||||
virt:
|
vm_template: fedora_34
|
||||||
host: localhost
|
|
||||||
image: fedora-34-x64.qcow2
|
|
||||||
cpus: 2
|
|
||||||
ram: 2048
|
|
||||||
hdd: 10g
|
|
||||||
|
@ -1,16 +1,20 @@
|
|||||||
---
|
---
|
||||||
|
- include_vars: vm_templates.yml
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
debug:
|
||||||
|
msg: "{{ vm_templates[item] }}"
|
||||||
|
loop: "{{ vm_templates|flatten(1) }}"
|
||||||
|
|
||||||
- name: fetch images
|
- name: fetch images
|
||||||
get_url:
|
get_url:
|
||||||
dest: "{{ libvirt.images }}/{{ item.dest }}"
|
dest: "{{ libvirt.images }}/{{ vm_templates[item].image.filename }}"
|
||||||
group: root
|
group: root
|
||||||
owner: root
|
owner: root
|
||||||
mode: u=rw,g=r,o=r
|
mode: u=rw,g=r,o=r
|
||||||
url: "{{ item.url }}"
|
url: "{{ vm_templates[item].image.url }}"
|
||||||
checksum: "{{ item.checksum }}"
|
checksum: "{{ vm_templates[item].image.checksum }}"
|
||||||
with_items:
|
loop: "{{ vm_templates|flatten(1) }}"
|
||||||
- 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
|
|
||||||
|
|
||||||
- name: virt_net "docker" present
|
- name: virt_net "docker" present
|
||||||
virt_net:
|
virt_net:
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
- name: create vm storage
|
- name: create vm storage
|
||||||
delegate_to: "{{ virt.host }}"
|
delegate_to: "{{ virt.host }}"
|
||||||
copy:
|
copy:
|
||||||
src: "{{ libvirt.images }}/{{ virt.image }}"
|
src: "{{ libvirt.images }}/{{ virt.image.filename }}"
|
||||||
dest: "{{ libvirt.images }}/{{ inventory_hostname }}.qcow2"
|
dest: "{{ libvirt.images }}/{{ inventory_hostname }}.qcow2"
|
||||||
force: no
|
force: no
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
---
|
---
|
||||||
|
- include_vars: vm_templates.yml
|
||||||
|
|
||||||
- name: check vm existance
|
- name: check vm existance
|
||||||
delegate_to: "{{ virt.host }}"
|
delegate_to: "{{ virt.host }}"
|
||||||
stat:
|
stat:
|
||||||
@ -6,8 +8,12 @@
|
|||||||
get_checksum: false
|
get_checksum: false
|
||||||
get_attributes: false
|
get_attributes: false
|
||||||
get_mime: false
|
get_mime: false
|
||||||
|
vars:
|
||||||
|
virt: "{{ vm_templates[vm_template] }}"
|
||||||
register: vmimg
|
register: vmimg
|
||||||
|
|
||||||
- name: create vm
|
- name: create vm
|
||||||
include_tasks: create_vm.yml
|
include_tasks: create_vm.yml
|
||||||
|
vars:
|
||||||
|
virt: "{{ vm_templates[vm_template] }}"
|
||||||
when: not vmimg.stat.exists
|
when: not vmimg.stat.exists
|
||||||
|
10
vm_templates.yml
Normal file
10
vm_templates.yml
Normal 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
|
Loading…
Reference in New Issue
Block a user