Skip to content

Instantly share code, notes, and snippets.

@thisdougb
Last active November 16, 2018 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisdougb/5e88e7a62b7a9f99620cb0a323ccbda5 to your computer and use it in GitHub Desktop.
Save thisdougb/5e88e7a62b7a9f99620cb0a323ccbda5 to your computer and use it in GitHub Desktop.
---
- hosts: localhost
vars:
mydomain: mytest.com
moons:
- moon
- deimos
- styx
tasks:
# actual: always retries the same 'item'
# expected: re-execute the random_choice on each retry
# NOT WORKING AS EXPECTED
- 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
# NOT WORKING AS EXPECTED
- name: (another not-working example) Reserve DNS cname to avoid race conditions, fail early!
route53:
state: present
zone: "{{ mydomain }}"
record: "{{ moons | random }}.{{ mydomain }}"
type: CNAME
ttl: 7200
value: 1.1.1.1
wait: no
overwrite: no
register: result
retries: 5
until: result.changed == true
# NOT WORKING AS EXPECTED
- name: (another not-working example) 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_items: "{{ moons | random }}"
until: result.changed == true
# WORKS AS EXPECTED: retry a task 2 times with random list elements supplied to the loop
#
- include: inner_loop_tasks.yml
loop: "{{ (moons | shuffle)[:2] }}"
# inner_loop_tasks.yml
# - 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
# when:
# - moon_name is not defined
#
# - set_fact:
# moon_name: "{{ item }}"
# when: result.changed == true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment