summaryrefslogtreecommitdiffstats
path: root/ansible/deployment_poc/tasks/netbox_query_ip.yml
blob: f807e4fc22cabb546aeb153301e7b9e3dcff247e (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
29
30
31
32
33
34
---
- name: Query existing address
  ansible.builtin.uri:
    url: "{{ endpoint }}/ipam/ip-addresses?virtual_machine_id={{ id }}"
    client_cert: "{{ cert }}"
    client_key: "{{ key }}"
    method: GET
    return_content: yes
    headers:
      Accept: application/json
      Authorization: "Token {{ token }}"
  register: nb_ip_1
  delegate_to: localhost
  tags:
    - init_dp
    - init_ssh

- name: Query available address
  ansible.builtin.uri:
    url: "{{ endpoint }}/ipam/prefixes/{{ prefix_id }}/available-ips/?limit=1"
    client_cert: "{{ cert }}"
    client_key: "{{ key }}"
    method: GET
    return_content: yes
    headers:
      Accept: application/json
      Authorization: "Token {{ token }}"
  register: nb_ip_2
  delegate_to: localhost
  when: "nb_ip_1.json.count|int == 0 or (nb_ip_1.json.results[0].status is defined and nb_ip_1.json.results[0].status.value != 'active')"
  tags:
    - init_dp
    - init_ssh