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