Discussion:
[ansible-project] Using set_fact along with do until group
Naween Ghimire
2015-07-17 11:59:49 UTC
Permalink
Hi I have a usecase where i have a string "dumb". During the execution of
play i create a new string by using a random filter and this string should
be any of ['duma','dumc','dumd'] but not "dumb". So i tried to use do until
loop as follows:

- hosts: local
connection: local
gather_facts: false
vars:
old_string: 'dumb'

tasks:
- name: Generate random number
set_fact: "new_string=dum{{ ['a','b','c','d'] |random }}"
register: e
until: e != old_string

- name: Fail if old number and new number are same
action: fail
when: new_string == old_string

So as far as i am concerned the check at the until step should avoid
allowing the new_string to be "dumb", but its not doing as expected. Any
suggestions ?
--
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 ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/df654928-188a-4cf3-aade-59dce7c887ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Brian Coca
2015-07-17 15:54:10 UTC
Permalink
try:
set_fact: "new_string=dum{{
(['a','b','c','d']|difference([old_string[-1]])) |random }}"

it should not need loop as you remove the old string ending from the
available list
--
Brian Coca
--
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 ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAJ5XC8nK9wQAV9qB_Ymy1kRZnOB%3DQPGYZH5vQynHkMsSZ2Uwdg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...