summaryrefslogtreecommitdiff
path: root/ansible/roles/proxmox_vm/tasks/get_ip.yaml
blob: 14a7e47dccb17f6506aaead3d5427cb69933e49f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
- name: "{{ fqdn }} : 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: "{{ fqdn }}: 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: "{{ fqdn }}: ip address result"
  ansible.builtin.debug:
    msg: "{{ fqdn }} ip address is {{ vm_ip }}"

- name: "{{ fqdn }}: set ip to {{ vm_ip }}"
  set_fact:
    ansible_host: "{{ vm_ip }}"