Are you interested in our Early Access Program (EAP)? This program allows you to preview code, test in your lab and provide feedback prior to General Availability (GA) release of all Infoblox products. If so, please click the link here.

API & Integration, DevOps,NetOps,SecOps

Reply

Register host record using next available IP and extensible attributes for network

[ Edited ]
Techie
Posts: 3
705     0

Hi 

I am trying to register a new host record using next available IP and on specific networks that matches extensible attributes with the parameters I specify for "Bucket" and "Site".

Today this is done using a Python-script see below snippet:

        create_next_ip_payload = {'name': self.args.hostname + self.domainname,
                                      'ipv4addrs': [{'ipv4addr': {
                                          '_object_function':'next_available_ip',
                                          '_object_field':'value',
                                          '_object':'network',
                                          '_object_parameters':{
                                              '*Bucket':self.bucket, '*Site':'my_site'},
                                          '_result_field':'ips',
                                          '_parameters':{'num':1}}}]}
        if self.args.verbose:
            print 'CREATING HOST RECORD {0}{1} IN BUCKET:{2}'.format(self.args.hostname, self.domainname, self.bucket)
        req_rec = requests.post(infoblox.URL + 'record:host', auth=(infoblox.USER, infoblox.PASS),
                                verify=False, json=create_next_ip_payload)

I wonder if it is possible to achive the above using Ansible module nios_host_record:
https://docs.ansible.com/ansible/latest/collections/infoblox/nios_modules/nios_host_record_module.ht...

 

I have tried to do this but I am not sure how to lookup the network using extensible attributes Bucket and Site in my case. If I do a search in the GUI using the parameters for Bucket and Site I get a list with about 20 matching networks. So I guees that the function next_available_ip handles this automatically if it receives multiple possible networks?

 

If it can´t be solved using the Ansible module, any suggestion how to do it using Curl?

Re: Register host record using next available IP and extensible attributes for network

Techie
Posts: 3
706     0

Some progress. I have manged to lookup all networks with extensible attributes:

Bucket: my_bucket

Site: my_site

Country: my_country

 

  - name: Search for Networks in bucket az-cross-general
    set_fact:
      az_networks: "{{ lookup('nios', 'network', filter={'*Bucket':'my_bucket','*Site':'my_site','*Country':'my_country'}, provider=nios_provider ) }}"

      # To return the list of networks including their extensible attributes
      az_networks: "{{ lookup('nios', 'network', filter={'*Bucket':'my_bucket','*Site':'my_site','*Country':'my_country'}, return_fields=['extattrs'], provider=nios_provider ) }}"

Now I will see if I can use this variable as input for to nios_next_ip and replace 192.168.10.0/24 with variable az_networks or if I need to trim the input in some way.

- name: Dynamically add host record to next available ip
  infoblox.nios_modules.nios_host_record:
    name: host.ansible.com
    ipv4:
      - address: {nios_next_ip: 192.168.10.0/24}

Re: Register host record using next available IP and extensible attributes for network

Techie
Posts: 3
706     0

Hi

 

Using json code in the  body seems to solve my issue

 

  - name: "Create Host record in Infoblox Test using URI module for {{ host_fqdn }}"
    uri:
      url: "{{ infoblox_url }}"
      user: "{{ infoblox_username }}"
      password: "{{ infoblox_password }}"
      method: POST
      body: '[{
  "method": "POST",
  "object": "record:host",
  "data": {
    "configure_for_dns": true,
    "ipv4addrs": [{
      "configure_for_dhcp": false,
      "ipv4addr": {
        "_object_function": "next_available_ip",
        "_result_field": "ips",
        "_object": "network",
        "_object_parameters": {
          "*Bucket": "{{ bucket }}",
          "*Site": "{{ site }}",
          "*Country": "{{ country }}"
        }
      }
    }],
    "name": "{{ host_fqdn }}",
    "comment": "{{ create_comment }}"
  },
  "args": {
    "_return_fields": "name,ipv4addrs,network_view,extattrs"
  }
}]'
      body_format: json
      status_code: 201,400
      validate_certs: no
    register: create_host
    changed_when: create_host.status == 201
Showing results for 
Search instead for 
Did you mean: 

Recommended for You