progress on vm_template
This commit is contained in:
parent
09d6c93224
commit
8daf2d1ff8
@ -2,4 +2,7 @@
|
||||
ansible_host: hv00.balsillie.net
|
||||
|
||||
vhd_template: "kube_template_vda.qcow2"
|
||||
root_vhd_pool_dir: "/vhds" # No trailing /
|
||||
root_vhd_pool_dir: "/vhds/root" # No trailing /
|
||||
data_vhd_pool_dir: "/vhds/data" # No trailing /
|
||||
firmware_vhd_pool_dir: "/vhds/firmware" # No trailing /
|
||||
containers_vhd_pool_dir: "/vhds/containers" # No trailing /
|
@ -5,6 +5,10 @@
|
||||
loop_var: vm_number
|
||||
block:
|
||||
|
||||
- name: set vm_name
|
||||
ansible.builtin.set_fact:
|
||||
vm_name: "{{ vm_name_prefix }}{{ vm_number }}"
|
||||
|
||||
- name: create root vhd from template
|
||||
ansible.builtin.shell:
|
||||
cmd: |
|
||||
@ -12,16 +16,16 @@
|
||||
-b {{ root_vhd_pool_dir }}/{{ vhd_template }} \
|
||||
-F qcow2 \
|
||||
-f qcow2 \
|
||||
{{ root_vhd_pool_dir }}/{{ vm_name_prefix }}{{ vm_number }}_vda.qcow2
|
||||
creates: "{{ root_vhd_pool_dir }}/{{ vm_name_prefix }}{{ vm_number }}_vda.qcow2"
|
||||
{{ root_vhd_pool_dir }}/{{ vm_name }}_vda.qcow2
|
||||
creates: "{{ root_vhd_pool_dir }}/{{ vm_name }}_vda.qcow2"
|
||||
register: root_vhd_created
|
||||
|
||||
# TODO check this template copy
|
||||
- name: copy network files in
|
||||
- name: copy network files to hypervisor host
|
||||
when: root_vhd_created is changed
|
||||
ansible.builtin.template:
|
||||
src: eno1.network.j2
|
||||
dest: /tmp/eno1_{{ vm_number }}.network
|
||||
dest: /tmp/eno1_{{ vm_name }}.network
|
||||
|
||||
- name: customize root vhd
|
||||
when: root_vhd_created is changed
|
||||
@ -29,26 +33,26 @@
|
||||
# TODO check virt customize command
|
||||
# TODO select host vars for vm_number for password and ssh string
|
||||
cmd: |
|
||||
virt-customize -a {{ root_vhd_pool_dir }}/{{ vm_name_prefix }}{{ vm_number }}_vda.qcow2 \
|
||||
virt-customize -a {{ root_vhd_pool_dir }}/{{ vm_name }}_vda.qcow2 \
|
||||
--format qcow2 \
|
||||
--hostname {{ vm_name_prefix }}{{ vm_number }}.{{ vm_domain }} \
|
||||
--copy-in /tmp/eno1_{{ vm_number }}.network:/etc/systemd/network/eno1.network \
|
||||
--append-line "/etc/hosts:127.0.1.1 {{ vm_name_prefix }}{{ vm_number }}.{{ vm_domain }} {{ vm_name_prefix }}{{ vm_number }}"
|
||||
--password ladmin:password:{{ }} \
|
||||
--hostname {{ vm_name }}.{{ vm_domain }} \
|
||||
--copy-in /tmp/eno1_{{ vm_name }}.network:/etc/systemd/network/eno1.network \
|
||||
--append-line "/etc/hosts:127.0.1.1 {{ vm_name }}.{{ vm_domain }} {{ vm_name }}"
|
||||
--password ladmin:password:{{ }} \
|
||||
--password-crypto sha512 \
|
||||
--ssh-inject 'ladmin:string:{{ }}'
|
||||
--ssh-inject "ladmin:string:{{ }}"
|
||||
|
||||
- name: create container storage vhd
|
||||
ansible.builtin.shell:
|
||||
cmd: |
|
||||
qemu-img create -f qcow2 {{ root_vhd_pool_dir }}/{{ vm_name_prefix }}{{ vm_number }}_vdb.qcow2 64G
|
||||
creates: "{{ root_vhd_pool_dir }}/{{ vm_name_prefix }}{{ vm_number }}_vdb.qcow2"
|
||||
qemu-img create -f qcow2 {{ containers_vhd_pool_dir }}/{{ vm_name }}_vdb.qcow2 64G
|
||||
creates: "{{ root_vhd_pool_dir }}/{{ vm_name }}_vdb.qcow2"
|
||||
|
||||
# - name: create data storage vhd
|
||||
# ansible.builtin.shell:
|
||||
# cmd: |
|
||||
# qemu-img create -f qcow2 {{ data_vhd_pool_dir }}/kube{{ vm_number }}_vdc.qcow2 4096G
|
||||
# creates: "{{ data_vhd_pool_dir }}/kube{{ vm_number }}_vdc.qcow2"
|
||||
# qemu-img create -f qcow2 {{ data_vhd_pool_dir }}/{{ vm_name }}_vdc.qcow2 4T
|
||||
# creates: "{{ data_vhd_pool_dir }}/{{ vm_name }}_vdc.qcow2"
|
||||
|
||||
- name: list vms
|
||||
community.libvirt.virt:
|
||||
@ -59,11 +63,12 @@
|
||||
community.libvirt.virt:
|
||||
command: define
|
||||
autostart: true
|
||||
name: "{{ vm_name_prefix }}{{ vm_number }}"
|
||||
name: "{{ vm_name }}"
|
||||
xml: "{{ lookup('template', 'vm_template.xml.j2') }}"
|
||||
when: not (vm_list contains {{ vm_name_prefix }}{{ vm_number }})
|
||||
# TODO check in list logic
|
||||
when: not (vm_list contains {{ vm_name }})
|
||||
|
||||
- name: start vm
|
||||
community.libvirt.virt:
|
||||
command: start
|
||||
name: "{{ vm_name_prefix }}{{ vm_number }}"
|
||||
state: started
|
||||
name: "{{ vm_name }}"
|
@ -1,5 +1,5 @@
|
||||
<domain type='kvm'>
|
||||
<name>{{ vm_name_prefix }}{{ vm_number }}</name>
|
||||
<name>{{ vm_name }}</name>
|
||||
<metadata>
|
||||
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
|
||||
<libosinfo:os id="http://archlinux.org/archlinux/rolling"/>
|
||||
@ -14,7 +14,7 @@
|
||||
<os>
|
||||
<type arch={{ vm_machine_arch }} machine={{ vm_machine_type }}>hvm</type>
|
||||
<loader readonly='yes' secure='yes' type='pflash'>/usr/share/edk2-ovmf/x64/OVMF_CODE.secboot.fd</loader>
|
||||
<nvram template=/usr/share/edk2-ovmf/x64/OVMF_VARS.fd>{{ fw_vars_pool_dir }}/{{ vm_name_prefix }}{{ vm_number }}_VARS.fd</nvram>
|
||||
<nvram template=/usr/share/edk2-ovmf/x64/OVMF_VARS.fd>{{ firmware_vhd_pool_dir }}/{{ vm_name }}_VARS.fd</nvram>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<features>
|
||||
@ -42,13 +42,13 @@
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2'/>
|
||||
<source file='{{ root_vhd_pool_dir }}/{{ vm_name_prefix }}{{ vm_number }}_vda.qcow2'/>
|
||||
<source file='{{ root_vhd_pool_dir }}/{{ vm_name }}_vda.qcow2'/>
|
||||
<target dev='vda' bus='virtio'/>
|
||||
<boot order='1'/>
|
||||
</disk>
|
||||
<disk type='file' device='disk'>
|
||||
<driver name='qemu' type='qcow2'/>
|
||||
<source file='{{ root_vhd_pool_dir }}/{{ vm_name_prefix }}{{ vm_number }}_vdb.qcow2'/>
|
||||
<source file='{{ containers_vhd_pool_dir }}/{{ vm_name }}_vdb.qcow2'/>
|
||||
<target dev='vdb' bus='virtio'/>
|
||||
</disk>
|
||||
<controller type='usb' index='0' model='qemu-xhci' ports='15'/>
|
||||
|
@ -1,7 +1,7 @@
|
||||
---
|
||||
|
||||
- name: sysprep the template vhd
|
||||
when: template_created is changed
|
||||
# when: template_created is changed
|
||||
ansible.builtin.shell:
|
||||
cmd: |
|
||||
virt-sysprep -a {{ root_vhd_pool_dir }}/{{ vhd_template }} \
|
||||
|
Loading…
Reference in New Issue
Block a user