69 lines
2.4 KiB
YAML
69 lines
2.4 KiB
YAML
|
---
|
||
|
- name: create k8s vms
|
||
|
with_items: "{{ vm_name_suffixes }}"
|
||
|
loop_control:
|
||
|
loop_var: vm_number
|
||
|
block:
|
||
|
|
||
|
- name: create root vhd from template
|
||
|
ansible.builtin.shell:
|
||
|
cmd: |
|
||
|
qemu-img create \
|
||
|
-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"
|
||
|
register: root_vhd_created
|
||
|
|
||
|
# TODO check this template copy
|
||
|
- name: copy network files in
|
||
|
when: root_vhd_created is changed
|
||
|
ansible.builtin.template:
|
||
|
src: eno1.network.j2
|
||
|
dest: /tmp/eno1_{{ vm_number }}.network
|
||
|
|
||
|
- name: customize root vhd
|
||
|
when: root_vhd_created is changed
|
||
|
ansible.builtin.shell:
|
||
|
# 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 \
|
||
|
--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:{{ }} \
|
||
|
--password-crypto sha512 \
|
||
|
--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"
|
||
|
|
||
|
# - 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"
|
||
|
|
||
|
- name: list vms
|
||
|
community.libvirt.virt:
|
||
|
command: list
|
||
|
register: vm_list
|
||
|
|
||
|
- name: define vm
|
||
|
community.libvirt.virt:
|
||
|
command: define
|
||
|
autostart: true
|
||
|
name: "{{ vm_name_prefix }}{{ vm_number }}"
|
||
|
xml: "{{ lookup('template', 'vm_template.xml.j2') }}"
|
||
|
when: not (vm_list contains {{ vm_name_prefix }}{{ vm_number }})
|
||
|
|
||
|
- name: start vm
|
||
|
community.libvirt.virt:
|
||
|
command: start
|
||
|
name: "{{ vm_name_prefix }}{{ vm_number }}"
|