Search IP adresses from nautobot and search inside dictionnary

Viewed 16

I'm currently using networktocode's autobot module for ansible and i'm trying to get an ip from a registered DNS entry.

For that, i use the api to extract the list of all registered ip addresses and make a loop to search within the result.

- name: "Search existing IP"
  set_fact:
    nautobot_query: "{{ query('networktocode.nautobot.lookup', 'ip-addresses',
                  api_endpoint='https://nautobot-url.fr',
                  api_version='1.3',
                  token='12312312312312312313') }}"

- name: "Set_fact when hostname matches"
  ansible.builtin.set_fact:
    ip_query: "{{ item.value.address }}"
    ip_id: "{{ item.value.id }}"
  loop: "{{ nautobot_query }}"
  when: ("{{ item.value.dns_name }}" == "{{ vm_name }}")
  no_log: true 

- name: "Message info nautobot"
  debug:
    msg: "Got existing IP : {{ ip_query }}"

That's a very verbose and hazardous solution, is there a better way to do that?

Either by extracting the IP address or making a better search within the result.

Thanks in advance.

0 Answers
Related