summaryrefslogtreecommitdiff
path: root/ansible/roles/proxmox_vm/tasks/get_ip.yaml
diff options
context:
space:
mode:
Diffstat (limited to 'ansible/roles/proxmox_vm/tasks/get_ip.yaml')
-rw-r--r--ansible/roles/proxmox_vm/tasks/get_ip.yaml29
1 files changed, 29 insertions, 0 deletions
diff --git a/ansible/roles/proxmox_vm/tasks/get_ip.yaml b/ansible/roles/proxmox_vm/tasks/get_ip.yaml
new file mode 100644
index 0000000..584b44d
--- /dev/null
+++ b/ansible/roles/proxmox_vm/tasks/get_ip.yaml
@@ -0,0 +1,29 @@
+---
+- name: "vmid {{ clone_result.vmid }}: getting config via proxmox api"
+ set_fact:
+ vm_config: "{{ lookup('url', config_url, validate_certs=False, headers=config_headers) }}"
+ vars:
+ config_url: "https://{{ proxmox_hostname }}:8006/api2/json/nodes/{{ proxmox_node }}/qemu/{{ clone_result.vmid }}/agent/network-get-interfaces"
+ config_headers:
+ Authorization: "PVEAPIToken={{ proxmox_username }}!{{ proxmox_api_token_id }}={{ proxmox_api_token_secret }}"
+
+- name: "vmid {{ clone_result.vmid }}: extracting ipv4 address"
+ set_fact:
+ vm_ip: >-
+ {{
+ vm_config['data']['result']
+ | map(attribute='ip-addresses')
+ | flatten
+ | selectattr("ip-address-type", "equalto", "ipv4")
+ | selectattr("ip-address", "ne", "127.0.0.1")
+ | map(attribute="ip-address")
+ | first
+ }}
+
+- name: "vmid {{ clone_result.vmid }}: ip address result"
+ ansible.builtin.debug:
+ msg: "vmid {{ clone_result.vmid }} ip address is {{ vm_ip }}"
+
+- name: "vmid {{ clone_result.vmid }}: set ip to {{ vm_ip }}"
+ set_fact:
+ ansible_host: "{{ vm_ip }}"