diff options
| author | spmfox <spmfox@foxwd.com> | 2023-05-29 11:07:09 -0400 |
|---|---|---|
| committer | spmfox <spmfox@foxwd.com> | 2023-05-29 11:07:09 -0400 |
| commit | 891bd795def59f9cdd359e317df4078a0f655033 (patch) | |
| tree | 84f095a5db9ec8cbfb2b787f14aeae8447f9cec4 | |
| parent | ff35c64d337a286ac2864c8403c1840e28bb23b1 (diff) | |
Adding support for multi-vm environment definition
| -rw-r--r-- | group_vars/all | 13 | ||||
| -rw-r--r-- | roles/libvirt/tasks/vm-check-duplicate.yml | 1 | ||||
| -rw-r--r-- | roles/libvirt/tasks/vm-check-exists.yml | 2 | ||||
| -rw-r--r-- | roles/libvirt/tasks/vm-install.yml | 2 | ||||
| -rw-r--r-- | roles/zfs/tasks/dataset-check-duplicate.yml | 1 | ||||
| -rw-r--r-- | vm-create.yml | 9 | ||||
| -rw-r--r-- | vm-delete.yml | 13 |
7 files changed, 24 insertions, 17 deletions
diff --git a/group_vars/all b/group_vars/all deleted file mode 100644 index 26a6a7c..0000000 --- a/group_vars/all +++ /dev/null @@ -1,13 +0,0 @@ -vm_name: "" -parent_dataset: "" -memory_mb: 2048 -cpus: 1 -disk_gb: 20 -disk_format: "raw" -os: "rhel-unknown" -kickstart: "" -iso_path: "" -network: "" -timezone: "America/New_York" -root_password: "{{ lookup('password', '/dev/null length=32 chars=ascii_letters,digits') }}" -root_ssh_key: "" diff --git a/roles/libvirt/tasks/vm-check-duplicate.yml b/roles/libvirt/tasks/vm-check-duplicate.yml index 5070cfd..5da0725 100644 --- a/roles/libvirt/tasks/vm-check-duplicate.yml +++ b/roles/libvirt/tasks/vm-check-duplicate.yml @@ -7,4 +7,3 @@ ansible.builtin.fail: msg: "VM {{ libvirt_vm_name }} is already in-use." when: libvirt_vm_name | string in vms_list.list_vms - diff --git a/roles/libvirt/tasks/vm-check-exists.yml b/roles/libvirt/tasks/vm-check-exists.yml index c6adf31..3b80f23 100644 --- a/roles/libvirt/tasks/vm-check-exists.yml +++ b/roles/libvirt/tasks/vm-check-exists.yml @@ -6,5 +6,5 @@ - name: Fail if VM does not exist ansible.builtin.fail: msg: "VM {{ libvirt_vm_name }} does not exist." - when: libvirt_vm_name | string not in vms_list.list_vms + when: libvirt_vm_name | string not in vms_list.list_vms diff --git a/roles/libvirt/tasks/vm-install.yml b/roles/libvirt/tasks/vm-install.yml index a194ae7..1582e30 100644 --- a/roles/libvirt/tasks/vm-install.yml +++ b/roles/libvirt/tasks/vm-install.yml @@ -1,7 +1,7 @@ - name: Copy kickstart file to destination filesystem ansible.builtin.template: src: "kickstart/{{ libvirt_vm_kickstart_file }}" - dest: "/{{ libvirt_vm_destination }}/{{ libvirt_vm_kickstart_file }}" + dest: "/{{ libvirt_vm_destination }}/{{ libvirt_vm_kickstart_file }}" - name: Create VM in destination filesystem ansible.builtin.command: 'virt-install --name {{ libvirt_vm_name }} --memory {{ libvirt_vm_memory }} --vcpus {{ libvirt_vm_vcpus }} --network {{ libvirt_vm_network }} --disk size={{ libvirt_vm_disk_size }},path=/{{ libvirt_vm_destination }}/{{ libvirt_vm_name }}.img,format={{ libvirt_vm_disk_format }} --location {{ libvirt_vm_iso_path }} --os-variant {{ libvirt_vm_os }} --initrd-inject=/{{ libvirt_vm_destination }}/{{ libvirt_vm_kickstart_file }} --extra-args="inst.ks=file:/{{ libvirt_vm_kickstart_file }}"' diff --git a/roles/zfs/tasks/dataset-check-duplicate.yml b/roles/zfs/tasks/dataset-check-duplicate.yml index 1272765..beda19f 100644 --- a/roles/zfs/tasks/dataset-check-duplicate.yml +++ b/roles/zfs/tasks/dataset-check-duplicate.yml @@ -8,4 +8,3 @@ ansible.builtin.fail: msg: "Dataset {{ zfs_dataset }} is already in-use." when: not zfs_dataset_exists_check.failed - diff --git a/vm-create.yml b/vm-create.yml index 323e11e..cfe9f8d 100644 --- a/vm-create.yml +++ b/vm-create.yml @@ -1,19 +1,28 @@ - hosts: all become: true + gather_facts: false tasks: - ansible.builtin.include_role: name: zfs tasks_from: dataset-check-duplicate.yml + apply: + delegate_to: "{{ hypervisor_host }}" - ansible.builtin.include_role: name: libvirt tasks_from: vm-check-duplicate.yml + apply: + delegate_to: "{{ hypervisor_host }}" - ansible.builtin.include_role: name: zfs tasks_from: dataset-create.yml + apply: + delegate_to: "{{ hypervisor_host }}" - ansible.builtin.include_role: name: libvirt tasks_from: vm-install.yml + apply: + delegate_to: "{{ hypervisor_host }}" diff --git a/vm-delete.yml b/vm-delete.yml index fb720e4..6907c84 100644 --- a/vm-delete.yml +++ b/vm-delete.yml @@ -1,27 +1,40 @@ - hosts: all become: true + gather_facts: false tasks: - ansible.builtin.include_role: name: zfs tasks_from: dataset-check-exists.yml + apply: + delegate_to: "{{ hypervisor_host }}" - ansible.builtin.include_role: name: libvirt tasks_from: vm-check-exists.yml + apply: + delegate_to: "{{ hypervisor_host }}" - ansible.builtin.include_role: name: libvirt tasks_from: vm-confirm-info.yml + apply: + delegate_to: "{{ hypervisor_host }}" - ansible.builtin.include_role: name: zfs tasks_from: dataset-confirm-info.yml + apply: + delegate_to: "{{ hypervisor_host }}" - ansible.builtin.include_role: name: libvirt tasks_from: vm-undefine.yml + apply: + delegate_to: "{{ hypervisor_host }}" - ansible.builtin.include_role: name: zfs tasks_from: dataset-destroy.yml + apply: + delegate_to: "{{ hypervisor_host }}" |
