Reply

Ansible lookups

Member
Posts: 1
603     0

Hi all,

 

I'm trying to use Infoblox with Ansible for both A-Record and PTR. How can I do this? I'm trying to find a fqdn from an ip, or an ip from a fqdn.

 

Thanks.

 

 

Re: Ansible lookups

Adviser
Posts: 163
603     0

Hi,

 

You can do so by using the lookup plugins in your playbook as below.

---

- hosts: localhost
  vars:
    nios_provider:
      host: grid-master
      username: admin
      password: infoblox

  connection: local
  tasks:
# Get the list of A records
   - name: get member list
     set_fact:
       arecords: "{{ lookup('nios', 'record:a', provider=nios_provider) }}"
   - name: display all A records
     debug:
       msg: "{{ arecords}}"
# Get an A record using its name
   - name: get A record
     set_fact:
       arecord: "{{ lookup('nios', 'record:a', filter={'name': 'a.demo.com'}, provider=nios_provider) }}"
   - name: display A record a.demo.com
     debug:
       msg: "{{ arecord}}"
# Get an A record using its IP address
   - name: get A record
     set_fact:
       arecord: "{{ lookup('nios', 'record:a', filter={'ipv4addr': '192.168.1.2'}, provider=nios_provider) }}"
   - name: display A record for 192.168.1.2
     debug:
       msg: "{{ arecord}}"
# Get all PTR records
   - name: get all PTR records
     set_fact:
       ptrrecord: "{{ lookup('nios', 'record:ptr', provider=nios_provider) }}"
   - name: display list of PTR records
     debug:
       msg: "{{ ptrrecord}}"
# Get PTR record using its name
   - name: get PTR record
     set_fact:
       ptrrecord: "{{ lookup('nios', 'record:ptr', filter={'ptrdname': 'a.demo.com'}, provider=nios_provider) }}"
   - name: display PTR record a.demo.com
     debug:
       msg: "{{ ptrrecord}}"

Hope this helps,

Krishna Vasudevan

Re: Ansible lookups

Member
Posts: 1
603     0

Is there any way to get records from specific dns view instead of getting all the records

Re: Ansible lookups

Adviser
Posts: 163
603     0

Hi,

 

You can add it as part of filters.

# Get an A record in a view
   - name: get A record
     set_fact:
       arecord: "{{ lookup('nios', 'record:a', filter={'view': 'test'}, provider=nios_provider) }}"
   - name: display A records in view test
     debug:
       msg: "{{ arecord}}"

Hope this helps,

Krishna

Re: Ansible lookups

[ Edited ]
Techie
Posts: 9
603     0

Like in GUI...how can we do global search using  lookup... For a single host i need to get return  all the types of records..  including IPV4 , VLAN, network_view, comments  and all the DNS related records aswell (a, cname, mx, ipv4, host..etc.) 

 

if i need to decom a server i need find all the entries related a single host/server ..using ansible

 

Re: Ansible lookups

Adviser
Posts: 163
603     0

Hi,

 

Can you try this and see if this is what you are looking for?

# Search against IP address
   - name: search for an IP address
     set_fact:
       iprecord: "{{ lookup('nios', 'search', filter={'address': '10.10.10.1'}, provider=nios_provider) }}"
   - name: display all the records associated with this IP address
     debug:
       msg: "{{ iprecord}}"

Regards,

Krishna

Re: Ansible lookups

[ Edited ]
Techie
Posts: 9
603     0

HI Krishna,

 

sorry its not working im using 

ansible --version
ansible 2.9.0

python version = 3.6.8 

 

Method 1 (which you suggestes)

Error:

Failed on object search with url https://infoblox.xxx.net/wapi/v2.1/search?address=10.12.131.81&_max_results=100000: b'{ "Error": "AdmConProtoError: Unknown argument/field: \'address\'", \n "code": "Client.Ibap.Proto", \n "text": "Unknown argument/field: \'address\'"\n}'
Failed on object search with url https://infoblox.xxx.net/wapi/v2.1/search?address=10.12.131.81&_max_results=100000&_proxy_search=GM: b'{ "Error": "AdmConProtoError: Unknown argument/field: \'address\'", \n "code": "Client.Ibap.Proto", \n "text": "Unknown argument/field: \'address\'"\n}'

========================================================

wif ref to

https://ipam.illinois.edu/wapidoc/objects/search.html

 

i tried Method 2: using ansible uri module GET method as below. this is also not working. 

url: "https://infoblox.xxx.net/wapi/v2.1/search?fqdn={{host}}"

user: "{{username}}"
password: "{{password}}"
force_basic_auth: yes
method: get

Error:

fatal: 1/1 [localhost]: FAILED! => {"cache_control": "no-cache, no-store", "changed": false, "connection": "close", "content": "{ \"Error\": \"AdmConProtoError: Unknown argument/field: 'fqdn'\", \n \"code\": \"Client.Ibap.Proto\", \n \"text\": \"Unknown argument/field: 'fqdn'\"\n}", "content_type": "application/json", "date": "Thu, 18 Feb 2021 22:24:59 GMT", "elapsed": 0, "json": {"Error": "AdmConProtoError: Unknown argument/field: 'fqdn'", "code": "Client.Ibap.Proto", "text": "Unknown argument/field: 'fqdn'"}, "msg": "Status code was 400 and not [200]: HTTP Error 400: Bad Request", "pragma": "no-cache", "redirected": false, "set_cookie": "ibapauth=\"client=API,group=READ%20ONLY,ctime=1613687099,timeout=28800,mtime=1613687099,ip=10.0.125.125,auth=TACACS%2B,user=xpctr570068,s0N5+7LTEN1FhBzE3slvjDAin28FRSK58k8\"; httponly; Path=/", "status": 400, "strict_transport_security": "max-age=31536000; includeSubDomains", "transfer_encoding": "chunked", "url": "https://infoblox.xxx.net/wapi/v2.1/search?fqdn=niostest19.xxx.test", "x_content_type_options": "nosniff", "x_frame_options": "SAMEORIGIN", "x_xss_protection": "1; mode=block"}

--------------------------------------------------------

========================================================================

this Method 3: is working with ip address

as like with uri module get method.

 

 url: "https://infoblox.xxx.net/wapi/v2.1/search?address=10.2.6.6 

user: "{{username}}"
password: "{{password}}"
force_basic_auth: yes
method: get

 

  but the result is  not bringing all the record ..only IP related record its bringing i need to get cname record also. will be easy if work with search?fqdn=

 

 

so please help for all the 3 methods.

Re: Ansible lookups

Techie
Posts: 9
603     0

Hi all any updates on this please

Re: Ansible lookups

Adviser
Posts: 163
603     0

Hi,

 

Looks like WAPI version 2.1 does not support the fqdn filter. You can try with a later version of WAPI like below:

API: https://grid-master.infoblox.com/wapi/v2.10/search?fqdn~=demo.com

Sample Output:
[
    {
        "_ref": "record:srv/ZG5zLmJpbmRfc3J2JC5fZGVmYXVsdC5jb20uaW5mb2Jsb3hkZW1vLmFkLl9tc2Rjcy9kYy5fc2l0ZXMuZGVmYXVsdC1maXJzdC1zaXRlLW5hbWUuX3RjcC5fbGRhcC8wLzEwMC8zODkvZGMyLmFkLmluZm9ibG94ZGVtby5jb20:_ldap._tcp.default-first-site-name._sites.dc._msdcs.ad.infobloxdemo.com/default",
        "name": "_ldap._tcp.default-first-site-name._sites.dc._msdcs.ad.infobloxdemo.com",
        "port": 389,
        "priority": 0,
        "target": "dc2.ad.infobloxdemo.com",
        "view": "default",
        "weight": 100
    },
    {
        "_ref": "record:a/ZG5zLmJpbmRfYSQuX2RlZmF1bHQuY29tLmluZm9ibG94ZGVtby5hZC5fbXNkY3MsZ2MsMTkyLjE2OC40LjIy:gc._msdcs.ad.infobloxdemo.com/default",
        "ipv4addr": "192.168.4.22",
        "name": "gc._msdcs.ad.infobloxdemo.com",
        "view": "default"
    },
.....]

In order to find the latest version of WAPI supported by your appliance, look at the values listed under supported_versions in the following API call:

API: https://grid-master.infoblox.com/wapi/v1.0/?_schema

Output:
{
    "requested_version": "1.0",
    "supported_objects": [
        "ipv4address",
        "ipv6address",
        "ipv6network",
        "ipv6networkcontainer",
        "ipv6range",
        "macfilteraddress",
        "network",
        "networkcontainer",
        "networkview",
        "range",
        "record:a",
        "record:aaaa",
        "record:cname",
        "record:host",
        "record:host_ipv4addr",
        "record:mx",
        "record:ptr",
        "record:srv",
        "record:txt",
        "search"
    ],
    "supported_versions": [
        "1.0",
        "1.1",
        "1.2",
        "1.2.1",
        "1.3",
        "1.4",
        "1.4.1",
        "1.4.2",
        "1.5",
        "1.6",
        "1.6.1",
        "1.7",
        "1.7.1",
        "1.7.2",
        "1.7.3",
        "1.7.4",
        "1.7.5",
        "2.0",
        "2.1",
        "2.1.1",
        "2.1.2",
        "2.10",
        "2.10.1",
        "2.10.2",
        "2.10.3",
        "2.10.5",
        "2.2",
        "2.2.1",
        "2.2.2",
        "2.3",
        "2.3.1",
        "2.4",
        "2.5",
        "2.6",
        "2.6.1",
        "2.7",
        "2.7.1",
        "2.7.2",
        "2.7.3",
        "2.8",
        "2.9",
        "2.9.1",
        "2.9.5"
    ]
}

Regards,

Krishna

Re: Ansible lookups

Techie
Posts: 9
603     0

@kvasudevan wrote:

Hi,

 

Looks like WAPI version 2.1 does not support the fqdn filter. You can try with a later version of WAPI like below:

API: https://grid-master.infoblox.com/wapi/v2.10/search?fqdn~=demo.com

Sample Output:
[
    {
        "_ref": "record:srv/ZG5zLmJpbmRfc3J2JC5fZGVmYXVsdC5jb20uaW5mb2Jsb3hkZW1vLmFkLl9tc2Rjcy9kYy5fc2l0ZXMuZGVmYXVsdC1maXJzdC1zaXRlLW5hbWUuX3RjcC5fbGRhcC8wLzEwMC8zODkvZGMyLmFkLmluZm9ibG94ZGVtby5jb20:_ldap._tcp.default-first-site-name._sites.dc._msdcs.ad.infobloxdemo.com/default",
        "name": "_ldap._tcp.default-first-site-name._sites.dc._msdcs.ad.infobloxdemo.com",
        "port": 389,
        "priority": 0,
        "target": "dc2.ad.infobloxdemo.com",
        "view": "default",
        "weight": 100
    },
    {
        "_ref": "record:a/ZG5zLmJpbmRfYSQuX2RlZmF1bHQuY29tLmluZm9ibG94ZGVtby5hZC5fbXNkY3MsZ2MsMTkyLjE2OC40LjIy:gc._msdcs.ad.infobloxdemo.com/default",
        "ipv4addr": "192.168.4.22",
        "name": "gc._msdcs.ad.infobloxdemo.com",
        "view": "default"
    },
.....]

In order to find the latest version of WAPI supported by your appliance, look at the values listed under supported_versions in the following API call:

API: https://grid-master.infoblox.com/wapi/v1.0/?_schema

Output:
{
    "requested_version": "1.0",
    "supported_objects": [
        "ipv4address",
        "ipv6address",
        "ipv6network",
        "ipv6networkcontainer",
        "ipv6range",
        "macfilteraddress",
        "network",
        "networkcontainer",
        "networkview",
        "range",
        "record:a",
        "record:aaaa",
        "record:cname",
        "record:host",
        "record:host_ipv4addr",
        "record:mx",
        "record:ptr",
        "record:srv",
        "record:txt",
        "search"
    ],
    "supported_versions": [
        "1.0",
        "1.1",
        "1.2",
        "1.2.1",
        "1.3",
        "1.4",
        "1.4.1",
        "1.4.2",
        "1.5",
        "1.6",
        "1.6.1",
        "1.7",
        "1.7.1",
        "1.7.2",
        "1.7.3",
        "1.7.4",
        "1.7.5",
        "2.0",
        "2.1",
        "2.1.1",
        "2.1.2",
        "2.10",
        "2.10.1",
        "2.10.2",
        "2.10.3",
        "2.10.5",
        "2.2",
        "2.2.1",
        "2.2.2",
        "2.3",
        "2.3.1",
        "2.4",
        "2.5",
        "2.6",
        "2.6.1",
        "2.7",
        "2.7.1",
        "2.7.2",
        "2.7.3",
        "2.8",
        "2.9",
        "2.9.1",
        "2.9.5"
    ]
}

Regards,

Krishna


Thanks its working


@kvasudevan wrote:

Hi,

 

Looks like WAPI version 2.1 does not support the fqdn filter. You can try with a later version of WAPI like below:

API: https://grid-master.infoblox.com/wapi/v2.10/search?fqdn~=demo.com

Sample Output:
[
    {
        "_ref": "record:srv/ZG5zLmJpbmRfc3J2JC5fZGVmYXVsdC5jb20uaW5mb2Jsb3hkZW1vLmFkLl9tc2Rjcy9kYy5fc2l0ZXMuZGVmYXVsdC1maXJzdC1zaXRlLW5hbWUuX3RjcC5fbGRhcC8wLzEwMC8zODkvZGMyLmFkLmluZm9ibG94ZGVtby5jb20:_ldap._tcp.default-first-site-name._sites.dc._msdcs.ad.infobloxdemo.com/default",
        "name": "_ldap._tcp.default-first-site-name._sites.dc._msdcs.ad.infobloxdemo.com",
        "port": 389,
        "priority": 0,
        "target": "dc2.ad.infobloxdemo.com",
        "view": "default",
        "weight": 100
    },
    {
        "_ref": "record:a/ZG5zLmJpbmRfYSQuX2RlZmF1bHQuY29tLmluZm9ibG94ZGVtby5hZC5fbXNkY3MsZ2MsMTkyLjE2OC40LjIy:gc._msdcs.ad.infobloxdemo.com/default",
        "ipv4addr": "192.168.4.22",
        "name": "gc._msdcs.ad.infobloxdemo.com",
        "view": "default"
    },
.....]

In order to find the latest version of WAPI supported by your appliance, look at the values listed under supported_versions in the following API call:

API: https://grid-master.infoblox.com/wapi/v1.0/?_schema

Output:
{
    "requested_version": "1.0",
    "supported_objects": [
        "ipv4address",
        "ipv6address",
        "ipv6network",
        "ipv6networkcontainer",
        "ipv6range",
        "macfilteraddress",
        "network",
        "networkcontainer",
        "networkview",
        "range",
        "record:a",
        "record:aaaa",
        "record:cname",
        "record:host",
        "record:host_ipv4addr",
        "record:mx",
        "record:ptr",
        "record:srv",
        "record:txt",
        "search"
    ],
    "supported_versions": [
        "1.0",
        "1.1",
        "1.2",
        "1.2.1",
        "1.3",
        "1.4",
        "1.4.1",
        "1.4.2",
        "1.5",
        "1.6",
        "1.6.1",
        "1.7",
        "1.7.1",
        "1.7.2",
        "1.7.3",
        "1.7.4",
        "1.7.5",
        "2.0",
        "2.1",
        "2.1.1",
        "2.1.2",
        "2.10",
        "2.10.1",
        "2.10.2",
        "2.10.3",
        "2.10.5",
        "2.2",
        "2.2.1",
        "2.2.2",
        "2.3",
        "2.3.1",
        "2.4",
        "2.5",
        "2.6",
        "2.6.1",
        "2.7",
        "2.7.1",
        "2.7.2",
        "2.7.3",
        "2.8",
        "2.9",
        "2.9.1",
        "2.9.5"
    ]
}

Regards,

Krishna


Thanks Krishna its working

Re: Ansible lookups

Member
Posts: 1
603     0

HI Krishna,

 

I am working on to get IP address associated with MAC. so by provising mac wanted to fetch IP details 

can you please suggest the ansible nios_lookup format to achive this.

I am doing below but not working

 

ipdetails: "{{ lookup('nios', 'search', filter={mac_address: '00:00:00:00:00:00'}, provider=nios_provider) }}"

Re: Ansible lookups

Adviser
Posts: 163
603     0

Hi,

 

Could you please share the error details? It would be easier for me to guide you with the actual query.

 

I tried this and it worked:

---
  
- hosts: localhost
  vars:
    nios_provider:
      host: grid-master.demo.com
      username: admin
      password: infoblox
      wapi_version: '2.10'

  connection: local
  tasks:
   - name: fetch options
     set_fact:
             host: "{{ lookup('nios', 'search', filter={'mac_address':'00:00:00:00:00:00'},provider=nios_provider) }}"
   - name: display options
     debug:
       msg: "{{ host }}"

Regards,

Krishna Vasudevan

Showing results for 
Search instead for 
Did you mean: 

Recommended for You