diff --git a/ansible/inventory/host_vars/hv00/hv00.yaml b/ansible/inventory/host_vars/hv00/hv00.yaml index 8ff7877..f2ec3d6 100644 --- a/ansible/inventory/host_vars/hv00/hv00.yaml +++ b/ansible/inventory/host_vars/hv00/hv00.yaml @@ -2,4 +2,7 @@ ansible_host: hv00.balsillie.net vhd_template: "kube_template_vda.qcow2" -root_vhd_pool_dir: "/vhds" # No trailing / \ No newline at end of file +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 / \ No newline at end of file diff --git a/ansible/roles/vm_deploy/tasks/main.yml b/ansible/roles/vm_deploy/tasks/main.yml index 6418d8d..d841328 100644 --- a/ansible/roles/vm_deploy/tasks/main.yml +++ b/ansible/roles/vm_deploy/tasks/main.yml @@ -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 }}" \ No newline at end of file + state: started + name: "{{ vm_name }}" \ No newline at end of file diff --git a/ansible/roles/vm_deploy/templates/vm_template.xml.j2 b/ansible/roles/vm_deploy/templates/vm_template.xml.j2 index 9d2e6b9..3a0817d 100644 --- a/ansible/roles/vm_deploy/templates/vm_template.xml.j2 +++ b/ansible/roles/vm_deploy/templates/vm_template.xml.j2 @@ -1,5 +1,5 @@ - {{ vm_name_prefix }}{{ vm_number }} + {{ vm_name }} @@ -14,7 +14,7 @@ hvm /usr/share/edk2-ovmf/x64/OVMF_CODE.secboot.fd - {{ fw_vars_pool_dir }}/{{ vm_name_prefix }}{{ vm_number }}_VARS.fd + {{ firmware_vhd_pool_dir }}/{{ vm_name }}_VARS.fd @@ -42,13 +42,13 @@ /usr/bin/qemu-system-x86_64 - + - + diff --git a/ansible/roles/vm_template/tasks/main.yml b/ansible/roles/vm_template/tasks/main.yml index 27a6f4c..d173b94 100644 --- a/ansible/roles/vm_template/tasks/main.yml +++ b/ansible/roles/vm_template/tasks/main.yml @@ -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 }} \