ahh, here's a better hack :)

retry 2 times with random list entries:

- include: inner_loop_tasks.yml loop: "{{ (moons | shuffle)[:2] }}" 

On Friday, 16 November 2018 14:26:14 UTC+1, Doug Bridgens wrote:
>
> Hi,
>
> I am trying to create new environments, each with a distinct name.  
> Multiple people can run the playbook to create an environment, so I have to 
> avoid conflicts.  I have a list of ~200 moon names, and I am trying to grab 
> an AWS DNS record (which I'm assuming is effectively atomic-ish).   If I 
> can get a DNS record, then I assume that the name is mine and continue to 
> use it to name the rest of my environment resources.
>
> I tried both random_choice and the random filter, but it seems that when 
> using 'retries' on a task the exact same task object is retried.  I had 
> this might re-exec the task and pick out a new random choice.   But I guess 
> the intention behind 'retries' is for when a resource (say an EC2 instance) 
> isn't available yet?
>
> What I am expecting is that I can get a new random choice on each retry.  
> What actually happens is that the same initial random choice is retried, 
> which makes this task either work first time or fail after five retries.
>
>         - name: Reserve DNS cname to avoid race conditions, fail early!
>           route53:
>               state: present
>               zone: "{{ mydomain }}"
>               record: "{{ item }}.{{ mydomain }}"
>               type: CNAME
>               ttl: 7200
>               value: 1.1.1.1
>               wait: no
>               overwrite: no
>           register: result
>           with_random_choice: "{{ moons }}"
>           retries: 5
>           until: result.changed == true
>
> (gist: https://gist.github.com/thisdougb/5e88e7a62b7a9f99620cb0a323ccbda5)
>
> Am I correct in thinking that the task is not going to be re-evaluated in 
> the retry mechanism?   I don't think this is a bug, but maybe the 
> documentation could be clearer about the implementation.   I could raise an 
> issue/doc-fix for that?
>
> Any alternative ways to achieve this ?
>
> cheers,
> Doug
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to