Select Page

A good friend of mine asked me the other day, “How does one update a CNAME in Infoblox using an Ansible Playbook.”
I told him to use the URI if it’s not available in the module, so he went looking on Google and didn’t come across a good example.
So I decided to write this quick post on “How To” use Ansible Playbook first to make a URI call to “GET” data and then take the “Response” and “Update” via another URI call.

We are going to update “bobhome.ansible.com” in my zone using the following API calls:

  • /wapi/v2.7/record:cname?name=bobhope.ansible.com
    • We will Search for “bobhope.ansible.com” with the above “GET” command
  • /wapi/v2.7/record:cname/ZG5zLmJpbmRfY25hbWUkLl9kZWZhdWx0LmNvbS5hbnNpYmxlLmRlbW8uY25hbWU:cname.demo.ansible.com/default
    • We will pass in the body {“name”:”bobhope.ansible.com”} using a “PUT” command
---
- hosts: localhost
  connection: local
  tasks:
 
  - name: Get the next available network from 10.1.0.0/16
    uri:
      url: "https://192.168.0.200/wapi/v2.7/record:cname?name=bobhope.ansible.com"
      method: GET
      user: admin
      password: infoblox
      status_code: 201, 302, 200
      headers:
          Content-Type: "application/json"
      body_format: json
      validate_certs: no
      return_content: yes
    register: data
 
  - name: CNAME _ref
    debug:
      var: data.json[0]._ref
 
  - name: Update CNAME
    uri:
      url: "https://192.168.0.200/wapi/v2.7/{{ data.json[0]._ref }}"
      method: PUT
      user: admin
      password: infoblox
      status_code: 201, 302, 200
      headers:
          Content-Type: "application/json"
      body:
        name: "bobhopelives.ansible.com"
      validate_certs: no

Let’s run the “playbook” and take a look at the results:

As you can see the CNAME is updated via Ansible URI Module playbook

Let me know if you found this useful and any others you would like to see in the comments below.

Sif Baksh Administrator
Principal Solutions Architect
As Principal Solutions Architect, Sif Baksh is responsible for the design of large-scale Core Services and Security systems. With 25 years of engineering experience in the computer and communications industry, Sif brings a depth of understanding of complex solutions for large and small organizations.
follow me