My use case: we use Infoblox for our DNS. What I'm trying to do is
automatically create a host record with the next available hostname that
isn't already in DNS. My plan was to loop through a formatted hostname,
incrementing a number in that hostname until a hostname is found that isn't
already in Infoblox. Here's what I have so far:
- name: Assign next available IP address in your choosen vlan
nios_host_record:
name: "{{ 'hostname%02d' | format(item) }}"
ipv4:
- address: {nios_next_ip: '1.1.1.0/24'}
state: present
view: Internal
provider: "{{ provider }}"
loop: "{{ range(1, 5 + 1)|list }}"
register: loop_result
ignore_errors: true
So for this example, in the DNS, there's already a hostname01, hostname02,
hostname03. The output will be:
TASK [Assign next available IP address in your choosen vlan]
*******************************************************************************************************************************
failed: [localhost] (item=1) => {"ansible_loop_var": "item", "attempts": 1,
"changed": false, "code": "Client.Ibap.Data.Conflict", "item": 1, "msg":
"The record 'hostname01' already exists.", "operation": "create_object",
"type": "AdmConDataError"}
failed: [localhost] (item=2) => {"ansible_loop_var": "item", "attempts": 1,
"changed": false, "code": "Client.Ibap.Data.Conflict", "item": 2, "msg":
"The record 'hostname02' already exists.", "operation": "create_object",
"type": "AdmConDataError"}
failed: [localhost] (item=3) => {"ansible_loop_var": "item", "attempts": 1,
"changed": false, "code": "Client.Ibap.Data.Conflict", "item": 3, "msg":
"The record 'hostname03' already exists.", "operation": "create_object",
"type": "AdmConDataError"}
changed: [localhost] => (item=4)
changed: [localhost] => (item=5)
I'd like it to stop processing the loop at item=4, since that's the first
success. I've messed with a few different until statements at the end but
nothing seems to really work. Thanks.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/3687c5df-e90d-4d50-af6c-38b467951ad3o%40googlegroups.com.