Infoblox Exchange Cybersecurity Roadshow 2020 – Join us!
North America | Europe | Middle East/Africa | Asia-Pacific

API & Integration

Reply

Infoblox lookup-plugin (Ansible) filter help

[ Edited ]
agittins
Techie
Posts: 1
1371     0

Hi,

 

I'm currently looking into using the nios modules in Ansible and want to start out by getting up to speed with the nios lookup-plugin.

I've successfully followed the example here: https://www.ansible.com/blog/infoblox-integration-in-ansible-2.5

 

Using this play:

 

---

- name: Infoblox host search play
  hosts: localhost
  vars:
    nios_provider:
      host: 10.10.10.10
      username: admin
      password: password
      wapi_version: 2.6.1

  connection: local

  tasks:
  - name: fetch specific host
    set_fact:
      host: "{{ lookup('nios', 'record:host', filter={'name': 'host1.network.local'}, provider=nios_provider) }}"

 

  - name: fetch all hosts
    set_fact:
      host: "{{ lookup('nios', 'record:host', provider=nios_provider) }}"

 

 

However, what I now want to do is progress this on so that I can search for hosts using a partial name match, e.g. look for a name that contains "network" or "dc1".

I've tried using:

 - filter={'name': '| regex_search(*network*)'}

 - filter={'name': 'regex_search(network)'}

 - filter={'name': 'regex_search((network))'}

 - filter={'name': 'regex_search((*network*))'}

 - filter={'name': '| match(network)'}

 - filter={'name': 'match(network)'}

 

All to no avail.

 

Does anyone know if doing this sort of partial filter is possible and, if so, how to do it (a filter example would be nice)?

 

Thanks,

Highlighted

Re: Infoblox lookup-plugin (Ansible) filter help

SaileshGiri
Techie
Posts: 7
1371     0

Hi,

 

Yes, it is possible to lookup NIOS using partial strings as filter.

You can modify the filter statement as:

 

filter={'name~':'yourstring'}

 

 

I have tried running this locally. My NIOS environment has host records across multiple dns views. I tried to search for all host records with substring "test".

 

Here is the code snippet:

   - name: get host list using partial string
     set_fact:
       host_list: "{{ lookup('nios', 'record:host', filter={'name~':'test'}, provider=nios_provider) }}"
   - name: display host list using partial string
     debug:
       msg: "{{ host_list }}"

And here is the output:

ok: [localhost] => {
    "msg": [
        {
            "_ref": "record:host/ZG5zLmhvc3QkLjMyLmNvbS50ZXN0em9uZS50ZXN0MTE:test11.testzone.com/default.ansibleNetView", 
            "ipv4addrs": [
                {
                    "_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuMzIuY29tLnRlc3R6b25lLnRlc3QxMS4xMC4wLjAuMTAu:10.0.0.10/test11.testzone.com/default.ansibleNetView", 
                    "configure_for_dhcp": false, 
                    "host": "test11.testzone.com", 
                    "ipv4addr": "10.0.0.10"
                }
            ], 
            "name": "test11.testzone.com", 
            "view": "default.ansibleNetView"
        }, 
        {
            "_ref": "record:host/ZG5zLmhvc3QkLjMzLmNvbS5hbnNpYmxlem9uZS50ZXN0MQ:test1.ansiblezone.com/ansibleDnsView", 
            "ipv4addrs": [
                {
                    "_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuMzMuY29tLmFuc2libGV6b25lLnRlc3QxLjEwLjAuMC4zLg:10.0.0.3/test1.ansiblezone.com/ansibleDnsView", 
                    "configure_for_dhcp": false, 
                    "host": "test1.ansiblezone.com", 
                    "ipv4addr": "10.0.0.3"
                }
            ], 
            "name": "test1.ansiblezone.com", 
            "view": "ansibleDnsView"
        }, 
        {
            "_ref": "record:host/ZG5zLmhvc3QkLjMzLmNvbS5hbnNpYmxlem9uZS50ZXN0NTU:test55.ansiblezone.com/ansibleDnsView", 
            "ipv4addrs": [
                {
                    "_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuMzMuY29tLmFuc2libGV6b25lLnRlc3Q1NS4xMC4wLjAuNC4:10.0.0.4/test55.ansiblezone.com/ansibleDnsView", 
                    "configure_for_dhcp": false, 
                    "host": "test55.ansiblezone.com", 
                    "ipv4addr": "10.0.0.4"
                }
            ], 
            "name": "test55.ansiblezone.com", 
            "view": "ansibleDnsView"
        }, 
        {
            "_ref": "record:host/ZG5zLmhvc3QkLl9kZWZhdWx0LmNvbS50ZXN0LnRlc3Qx:test1.test.com/default", 
            "ipv4addrs": [
                {
                    "_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQuY29tLnRlc3QudGVzdDEuMS4xLjEuMTAwLg:1.1.1.100/test1.test.com/default", 
                    "configure_for_dhcp": false, 
                    "host": "test1.test.com", 
                    "ipv4addr": "1.1.1.100"
                }
            ], 
            "name": "test1.test.com", 
            "view": "default"
        }
    ]
}
Showing results for 
Search instead for 
Do you mean 

Recommended for You