2022-10-23 09:54:34 -04:00
|
|
|
---
|
|
|
|
- name: create k8s vms
|
|
|
|
with_items: "{{ vm_name_suffixes }}"
|
|
|
|
loop_control:
|
|
|
|
loop_var: vm_number
|
|
|
|
block:
|
|
|
|
|
2022-10-24 05:53:50 -04:00
|
|
|
- name: set vm_name
|
|
|
|
ansible.builtin.set_fact:
|
|
|
|
vm_name: "{{ vm_name_prefix }}{{ vm_number }}"
|
|
|
|
|
2022-10-23 09:54:34 -04:00
|
|
|
- name: create root vhd from template
|
|
|
|
ansible.builtin.shell:
|
|
|
|
cmd: |
|
|
|
|
qemu-img create \
|
|
|
|
-b {{ root_vhd_pool_dir }}/{{ vhd_template }} \
|
|
|
|
-F qcow2 \
|
|
|
|
-f qcow2 \
|
2022-10-24 05:53:50 -04:00
|
|
|
{{ root_vhd_pool_dir }}/{{ vm_name }}_vda.qcow2
|
|
|
|
creates: "{{ root_vhd_pool_dir }}/{{ vm_name }}_vda.qcow2"
|
2022-10-23 09:54:34 -04:00
|
|
|
register: root_vhd_created
|
|
|
|
|
|
|
|
# TODO check this template copy
|
2022-10-24 05:53:50 -04:00
|
|
|
- name: copy network files to hypervisor host
|
2022-10-23 09:54:34 -04:00
|
|
|
when: root_vhd_created is changed
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: eno1.network.j2
|
2022-10-24 05:53:50 -04:00
|
|
|
dest: /tmp/eno1_{{ vm_name }}.network
|
2022-10-23 09:54:34 -04:00
|
|
|
|
|
|
|
- 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: |
|
2022-10-24 05:53:50 -04:00
|
|
|
virt-customize -a {{ root_vhd_pool_dir }}/{{ vm_name }}_vda.qcow2 \
|
2022-10-23 09:54:34 -04:00
|
|
|
--format qcow2 \
|
2022-10-24 05:53:50 -04:00
|
|
|
--hostname {{ vm_name }}.{{ vm_domain }} \
|
2022-10-29 09:32:27 -04:00
|
|
|
--copy-in /tmp/eno1_{{ vm_name }}.network:/etc/systemd/network/10-eno1.network \
|
2022-10-24 05:53:50 -04:00
|
|
|
--append-line "/etc/hosts:127.0.1.1 {{ vm_name }}.{{ vm_domain }} {{ vm_name }}"
|
2022-10-29 09:32:27 -04:00
|
|
|
--password ladmin:password:{{ hostvars[vm_name]['ansible_become_pass'] }} \
|
|
|
|
--root-password password:{{ hostvars[vm_name]['ansible_root_pass'] }} \
|
2022-10-23 09:54:34 -04:00
|
|
|
--password-crypto sha512 \
|
2022-10-24 05:53:50 -04:00
|
|
|
--ssh-inject "ladmin:string:{{ }}"
|
2022-10-23 09:54:34 -04:00
|
|
|
|
|
|
|
- name: create container storage vhd
|
|
|
|
ansible.builtin.shell:
|
|
|
|
cmd: |
|
2022-10-24 05:53:50 -04:00
|
|
|
qemu-img create -f qcow2 {{ containers_vhd_pool_dir }}/{{ vm_name }}_vdb.qcow2 64G
|
|
|
|
creates: "{{ root_vhd_pool_dir }}/{{ vm_name }}_vdb.qcow2"
|
2022-10-23 09:54:34 -04:00
|
|
|
|
|
|
|
# - name: create data storage vhd
|
|
|
|
# ansible.builtin.shell:
|
|
|
|
# cmd: |
|
2022-10-24 05:53:50 -04:00
|
|
|
# qemu-img create -f qcow2 {{ data_vhd_pool_dir }}/{{ vm_name }}_vdc.qcow2 4T
|
|
|
|
# creates: "{{ data_vhd_pool_dir }}/{{ vm_name }}_vdc.qcow2"
|
2022-10-23 09:54:34 -04:00
|
|
|
|
|
|
|
- name: list vms
|
|
|
|
community.libvirt.virt:
|
|
|
|
command: list
|
|
|
|
register: vm_list
|
|
|
|
|
|
|
|
- name: define vm
|
|
|
|
community.libvirt.virt:
|
|
|
|
command: define
|
|
|
|
autostart: true
|
2022-10-24 05:53:50 -04:00
|
|
|
name: "{{ vm_name }}"
|
2022-10-23 09:54:34 -04:00
|
|
|
xml: "{{ lookup('template', 'vm_template.xml.j2') }}"
|
2022-10-24 05:53:50 -04:00
|
|
|
# TODO check in list logic
|
|
|
|
when: not (vm_list contains {{ vm_name }})
|
2022-10-23 09:54:34 -04:00
|
|
|
|
|
|
|
- name: start vm
|
|
|
|
community.libvirt.virt:
|
2022-10-24 05:53:50 -04:00
|
|
|
state: started
|
|
|
|
name: "{{ vm_name }}"
|