Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Ansible & Infoblox return_facts and Variables
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2018 07:50 AM
2203     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
Labels:
Re: Ansible & Infoblox return_facts and Variables
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2021 03:38 AM
2203     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