finalise vm_deploy role
This commit is contained in:
parent
03700ba0fb
commit
239ababf1d
@ -1,2 +1,3 @@
|
|||||||
---
|
---
|
||||||
ansible_host: kube01.balsillie.net
|
ansible_host: kube01.balsillie.net
|
||||||
|
ssh_public_key_string: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGtk+mk1+J3sZ3CA/yS7XV2wH913IdJj0gznmb/nI2nV ladmin@kube01.balsillie.net
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
---
|
---
|
||||||
ansible_host: kube02.balsillie.net
|
ansible_host: kube02.balsillie.net
|
||||||
|
ssh_public_key_string: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGOfsOJJJ34VT9mHv9moHQAQNTAok8sOr49rVTkIfDn9 ladmin@kube02.balsillie.net
|
||||||
|
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
---
|
---
|
||||||
ansible_host: kube03.balsillie.net
|
ansible_host: kube03.balsillie.net
|
||||||
|
ssh_public_key_string: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINFqYq3CcxziLbWfp/0VpO5uD/HyjiKTXD8t/dAS01Oq ladmin@kube00.balsillie.net
|
||||||
|
@ -9,6 +9,19 @@
|
|||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
vm_name: "{{ vm_name_prefix }}{{ vm_number }}"
|
vm_name: "{{ vm_name_prefix }}{{ vm_number }}"
|
||||||
|
|
||||||
|
- name: list vms
|
||||||
|
community.libvirt.virt:
|
||||||
|
command: list_vms
|
||||||
|
register: vm_list
|
||||||
|
|
||||||
|
- name: debug vm list
|
||||||
|
ansible.builtin.debug:
|
||||||
|
var: vm_list.list_vms
|
||||||
|
|
||||||
|
- name: proceed if vm does not exist
|
||||||
|
when: vm_name not in vm_list.list_vms
|
||||||
|
block:
|
||||||
|
|
||||||
- name: create root vhd from template
|
- name: create root vhd from template
|
||||||
ansible.builtin.shell:
|
ansible.builtin.shell:
|
||||||
cmd: |
|
cmd: |
|
||||||
@ -20,7 +33,6 @@
|
|||||||
creates: "{{ root_vhd_pool_dir }}/{{ vm_name }}_vda.qcow2"
|
creates: "{{ root_vhd_pool_dir }}/{{ vm_name }}_vda.qcow2"
|
||||||
register: root_vhd_created
|
register: root_vhd_created
|
||||||
|
|
||||||
# TODO check this template copy
|
|
||||||
- name: copy network files to hypervisor host
|
- 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:
|
||||||
@ -30,8 +42,6 @@
|
|||||||
- name: customize root vhd
|
- name: customize root vhd
|
||||||
when: root_vhd_created is changed
|
when: root_vhd_created is changed
|
||||||
ansible.builtin.shell:
|
ansible.builtin.shell:
|
||||||
# TODO check virt customize command
|
|
||||||
# TODO select host vars for vm_number for password and ssh string
|
|
||||||
cmd: |
|
cmd: |
|
||||||
virt-customize -a {{ root_vhd_pool_dir }}/{{ vm_name }}_vda.qcow2 \
|
virt-customize -a {{ root_vhd_pool_dir }}/{{ vm_name }}_vda.qcow2 \
|
||||||
--format qcow2 \
|
--format qcow2 \
|
||||||
@ -41,7 +51,12 @@
|
|||||||
--password ladmin:password:{{ hostvars[vm_name]['ansible_become_pass'] }} \
|
--password ladmin:password:{{ hostvars[vm_name]['ansible_become_pass'] }} \
|
||||||
--root-password password:{{ hostvars[vm_name]['ansible_root_pass'] }} \
|
--root-password password:{{ hostvars[vm_name]['ansible_root_pass'] }} \
|
||||||
--password-crypto sha512 \
|
--password-crypto sha512 \
|
||||||
--ssh-inject "ladmin:string:{{ hostvars[vm_name]['ssh_public_key_data'] }}"
|
--ssh-inject "ladmin:string:{{ hostvars[vm_name]['ssh_public_key_string'] }}"
|
||||||
|
|
||||||
|
- name: cleanup network files on hypervisor host
|
||||||
|
ansible.builtin.file:
|
||||||
|
state: absent
|
||||||
|
path: /tmp/eno1_{{ vm_name }}.network
|
||||||
|
|
||||||
- name: create container storage vhd
|
- name: create container storage vhd
|
||||||
ansible.builtin.shell:
|
ansible.builtin.shell:
|
||||||
@ -61,19 +76,12 @@
|
|||||||
qemu-img create -f qcow2 {{ data_hdd_vhd_pool_dir }}/{{ vm_name }}_vdd.qcow2 4T
|
qemu-img create -f qcow2 {{ data_hdd_vhd_pool_dir }}/{{ vm_name }}_vdd.qcow2 4T
|
||||||
creates: "{{ data_hdd_vhd_pool_dir }}/{{ vm_name }}_vdd.qcow2"
|
creates: "{{ data_hdd_vhd_pool_dir }}/{{ vm_name }}_vdd.qcow2"
|
||||||
|
|
||||||
- name: list vms
|
|
||||||
community.libvirt.virt:
|
|
||||||
command: list
|
|
||||||
register: vm_list
|
|
||||||
|
|
||||||
- name: define vm
|
- name: define vm
|
||||||
community.libvirt.virt:
|
community.libvirt.virt:
|
||||||
command: define
|
command: define
|
||||||
autostart: true
|
autostart: false
|
||||||
name: "{{ vm_name }}"
|
name: "{{ vm_name }}"
|
||||||
xml: "{{ lookup('template', 'vm_template.xml.j2') }}"
|
xml: "{{ lookup('template', 'vm_template.xml.j2') }}"
|
||||||
# TODO check in list logic
|
|
||||||
when: not (vm_list contains {{ vm_name }})
|
|
||||||
|
|
||||||
- name: start vm
|
- name: start vm
|
||||||
community.libvirt.virt:
|
community.libvirt.virt:
|
||||||
|
Loading…
Reference in New Issue
Block a user