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

Ansible & Infoblox return_facts and Variables

Techie
Posts: 2
6769     0

Hi All

I wrote a simple play to add a host entry using Ansible to Infoblox

 

As per below all works no problem

---
- hosts: localhost
  connection: local
  gather_facts: true
  tasks:
    - name: Create a Host Record in 11.11.11/24 for "bslnetworks.com"
      nios_host_record:
       name: router1-loopback0.bslnetworks.com
       ipv4:
         - address: 11.11.11.17
       state: present
       provider:
         host: 10.61.246.190
         username: admin
         password: adm1n

 

Now what im trying to do is set a fact or register a variable to the value of the ip address so that i can reuse that variable value.

 

I've tried these so far and with no luck

 

    - name: Set a fact ....
      set_fact:
       loopback0:
         "{{ lookup('nios', 'record:host', filter={'name':'router1-loopback0.bslnetworks.com'}, provider={'host': '10.61.246.190', 'username': 'admin', 'password': 'adm1n'}) }}"
    - debug: var=loopback0


    - name: set another fact
      set_fact:
       newfact=ansible_facts.ipv4.address
    - debug: var=newfact

I can't seem to quite get there and if anyone could offer any help it would be much appreciated

Cheers

RichB

 

Re: Ansible & Infoblox return_facts and Variables

Member
Posts: 1
6770     0

I don't know if you ever got the answer to this.

But I did the following (I later use the IP in another playbook in my Tower Workflow):

  tasks:
    - name: Return next available IP address for network X.X.X.X/24
      set_fact:
       vm_ipaddr: "{{ lookup('nios_next_ip', 'X.X.X.X/24', provider=nios_provider)[0] }}"
	   
    - name: Set IP stat for future playbook in workflow
      set_stats:
        data:
          vm_ip:  "{{ vm_ipaddr }}"
    
    - name: Configure an IPv4 host record
      nios_host_record:
        name: "{{ vm_name }}.example.com"
        ipv4addrs:
          - ipv4addr:
              "{{ vm_ipaddr }}"
        state: present
        provider: "{{ nios_provider }}"
        view: XXXXX

 

Showing results for 
Search instead for 
Did you mean: 

Recommended for You