Infoblox Guide

    You can review simple example tasks in the documentation for any of the or look at the Use cases with modules section for more elaborate examples. See the website for more information on the Infoblox product.

    Note

    You can retrieve most of the example playbooks used in this guide from the network-automation/infoblox_ansible GitHub repository.

    Before using Ansible modules with Infoblox, you must install the infoblox-client on your Ansible control node:

    Note

    You need an NIOS account with the WAPI feature enabled to use Ansible with Infoblox.

    To use Infoblox nios modules in playbooks, you need to configure the credentials to access your Infoblox system. The examples in this guide use credentials stored in <playbookdir>/group_vars/nios.yml. Replace these values with your Infoblox credentials:

    1. ---
    2. nios_provider:
    3. host: 192.0.0.2
    4. username: admin
    5. password: ansible

    Ansible includes the following lookup plugins for NIOS:

    • Uses the Infoblox WAPI API to fetch NIOS specified objects, for example network views, DNS views, and host records.
    • nios_next_ip Provides the next available IP address from a network. You’ll see an example of this in .
    • nios_next_network - Returns the next available network range for a network-container.

    To retrieve all network views and save them in a variable, use the module with the nios lookup plugin:

    1. ---
    2. - hosts: nios
    3. connection: local
    4. tasks:
    5. - name: fetch all networkview objects
    6. set_fact:
    7. networkviews: "{{ lookup('nios', 'networkview', provider=nios_provider) }}"
    8.  
    9. - name: check the networkviews
    10. debug:
    11. var: networkviews

    Retrieving a host record

    To retrieve a set of host records, use the set_fact module with the nios lookup plugin and include a filter for the specific hosts you want to retrieve:

    If you run this get_host_record.yml playbook, you should see results similar to the following:

    1. $ ansible-playbook get_host_record.yml
    2.  
    3. PLAY [localhost] ***************************************************************************************
    4.  
    5. TASK [fetch host leaf01] ******************************************************************************
    6. ok: [localhost]
    7.  
    8. TASK [check the leaf01 return variable] *************************************************************
    9. ok: [localhost] => {
    10. < ...output shortened...>
    11. "host": {
    12. {
    13. "configure_for_dhcp": false,
    14. "host": "leaf01.ansible.com",
    15. }
    16. ],
    17. "name": "leaf01.ansible.com",
    18. "view": "default"
    19. }
    20. }
    21.  
    22. TASK [debug specific variable (ipv4 address)] ******************************************************
    23. ok: [localhost] => {
    24. "host.ipv4addrs[0].ipv4addr": "192.168.1.11"
    25. }
    26.  
    27. TASK [fetch host leaf02] ******************************************************************************
    28. ok: [localhost]
    29.  
    30. TASK [check the leaf02 return variable] *************************************************************
    31. ok: [localhost] => {
    32. < ...output shortened...>
    33. "host": {
    34. "ipv4addrs": [
    35. {
    36. "configure_for_dhcp": false,
    37. "host": "leaf02.example.com",
    38. "ipv4addr": "192.168.1.12"
    39. }
    40. ],
    41. }
    42. }
    43.  
    44. PLAY RECAP ******************************************************************************************
    45. localhost : ok=5 changed=0 unreachable=0 failed=0

    The output above shows the host record for and leaf02.ansible.com that were retrieved by the nios lookup plugin. This playbook saves the information in variables which you can use in other playbooks. This allows you to use Infoblox as a single source of truth to gather and use information that changes dynamically. See for more information on using Ansible variables. See the nios examples for more data options that you can retrieve.

    You can access these playbooks at .

    You can use the nios modules in tasks to simplify common Infoblox workflows. Be sure to set up your NIOS credentials before following these examples.

    To configure an IPv4 network, use the module:

    1. ---
    2. - hosts: nios
    3. connection: local
    4. tasks:
    5. - name: Create a network on the default network view
    6. nios_network:
    7. network: 192.168.100.0/24
    8. options:
    9. - name: domain-name
    10. value: ansible.com
    11. state: present
    12. provider: "{{nios_provider}}"

    Notice the last parameter, provider, uses the variable nios_provider defined in the group_vars/ directory.

    Creating a host record

    Notice the IPv4 address in this example uses the nios_next_ip lookup plugin to find the next available IPv4 address on the network.

    To configure a forward DNS zone use, the nios_zone module:

    1. ---
    2. - hosts: nios
    3. connection: local
    4. tasks:
    5. - name: Create a forward DNS zone called ansible-test.com
    6. nios_zone:
    7. name: ansible-test.com
    8. comment: local DNS zone
    9. state: present
    10. provider: "{{ nios_provider }}"

    Creating a reverse DNS zone

    To configure a reverse DNS zone:

    1. ---
    2. - hosts: nios
    3. connection: local
    4. tasks:
    5. - name: configure a reverse mapping zone on the system using IPV6 zone format
    6. nios_zone:
    7. name: 100::1/128
    8. zone_format: IPV6
    9. state: present
    10. provider: "{{ nios_provider }}"

    You can use the Infoblox dynamic inventory script to import your network node inventory with Infoblox NIOS. To gather the inventory from Infoblox, you need two files:

    • - A file that specifies the NIOS provider arguments and optional filters.
    • infoblox.py - The python script that retrieves the NIOS inventory.

    To use the Infoblox dynamic inventory script:

    • Download the file and save it in the /etc/ansible directory.
    • Modify the infoblox.yaml file with your NIOS credentials.
    • Download the infoblox.py file and save it in the /etc/ansible/hosts directory.
    • Change the permissions on the infoblox.py file to make the file an executable:

    You can optionally use ./infoblox.py —list to test the script. After a few minutes, you should see your Infoblox inventory in JSON format. You can explicitly use the Infoblox dynamic inventory script as follows:

    1. $ ansible -i infoblox.py all -m ping

    You can also implicitly use the Infoblox dynamic inventory script by including it in your inventory directory (etc/ansible/hosts by default). See for more details.

    See also