diff options
author | Georg | 2022-01-05 23:59:13 +0100 |
---|---|---|
committer | Georg | 2022-01-05 23:59:13 +0100 |
commit | 7bb88aaa661dc6756e862562c47368de11657f44 (patch) | |
tree | 545d6f1d86c1d42ed04d558450996c54fdca631d /ansible/deployment_poc/tasks/configure_libvirt.yml | |
parent | 0e53f4d766e95205b20951fd252f6118ce05352b (diff) | |
download | system-7bb88aaa661dc6756e862562c47368de11657f44.tar.gz system-7bb88aaa661dc6756e862562c47368de11657f44.tar.bz2 system-7bb88aaa661dc6756e862562c47368de11657f44.zip |
Init Ansible NetBox DHCP POC deployment
Signed-off-by: Georg <georg@lysergic.dev>
Diffstat (limited to 'ansible/deployment_poc/tasks/configure_libvirt.yml')
-rw-r--r-- | ansible/deployment_poc/tasks/configure_libvirt.yml | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/ansible/deployment_poc/tasks/configure_libvirt.yml b/ansible/deployment_poc/tasks/configure_libvirt.yml new file mode 100644 index 0000000..b3e49b6 --- /dev/null +++ b/ansible/deployment_poc/tasks/configure_libvirt.yml @@ -0,0 +1,61 @@ +--- +- name: Provision VM + block: + - name: Create domain template + ansible.builtin.template: + src: "../templates/libvirt-template.xml.j2" + dest: "../templates/libvirt-{{ inventory_hostname }}.xml" + group: lysergic + mode: '0660' + + - name: Create storage template + ansible.builtin.template: + src: "../templates/libvirt-storage-template.xml.j2" + dest: "../templates/generated/libvirt-storage-{{ inventory_hostname }}.xml" + group: lysergic + mode: '0660' + + - name: Define domain + virt: + uri: "{{ libvirt_url }}" + command: define + xml: "{{ lookup('template', '../templates/libvirt-template.xml.j2') }}" + autostart: no + # delegate_to: localhost + + - name: Query volumes + ansible.builtin.command: + argv: + - /usr/bin/virsh + - -c + - "{{ libvirt_url }}" + - vol-list + - "{{ storage.name }}" + register: volumes + no_log: true + + - name: Define volume + ansible.builtin.command: + argv: + - /usr/bin/virsh + - -c + - "{{ libvirt_url }}" + - vol-create + - "{{ storage.name }}" + - "../templates/generated/libvirt-storage-{{ inventory_hostname }}.xml" + when: vm_name not in volumes.stdout + + - name: Fetch MAC address + ansible.builtin.shell: "/usr/bin/virsh -c {{ libvirt_url }} domiflist {{ vm_name }} | awk '{print $5}' | cut -d/ -f 1 | tail -n 2 | head -n1" # ewww :-( + register: domiflist_mac + + - name: Store MAC address + set_fact: + mac_address: "{{ domiflist_mac.stdout }}" + + delegate_to: localhost + + always: + - name: Debug + ansible.builtin.debug: + msg: "{{ libvirt_url if libvirt_url is defined }} - {{ storage.name if storage is defined }} - {{ mac_address if mac_address is defined }}" |