So I tried using the nios module to query hostnames but I couldn't find a
way to query part of a hostname. It seemed that it only accepted exact
names. Is this something you've done before?
On Thursday, June 25, 2020 at 1:22:23 PM UTC-4, Stefan Hornburg (Racke)
wrote:
>
> On 6/25/20 3:51 PM, Cade Lambert wrote:
> > 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
> >
>
> Hello Cade,
>
> you could query first the existing DNS records in Infoblox and determine
> the next hostname from these results.
>
> Regards
> Racke
>
> > 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] <javascript:> <mailto:
> [email protected] <javascript:>>.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/ansible-project/3687c5df-e90d-4d50-af6c-38b467951ad3o%40googlegroups.com
>
> > <
> https://groups.google.com/d/msgid/ansible-project/3687c5df-e90d-4d50-af6c-38b467951ad3o%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
>
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
>
--
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/5c53d589-f668-41ce-babe-6ff3576bdbd9o%40googlegroups.com.