# Using set\_fact along with do until group

**URL:** <https://forum.ansible.com/t/using-set-fact-along-with-do-until-group/18797>\
**Category:** Ansible Project\
**Created:** [July 17, 2015, 11:59am UTC](https://forum.ansible.com/t/using-set-fact-along-with-do-until-group/18797 "2015-07-17T11:59:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naween\_Ghimire](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@Naween\_Ghimire](https://forum.ansible.com/u/Naween_Ghimire)\
**Post date:** [July 17, 2015, 11:59am UTC](https://forum.ansible.com/t/using-set-fact-along-with-do-until-group/18797/1 "2015-07-17T11:59:49Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [July 17, 2015, 3:54pm UTC](https://forum.ansible.com/t/using-set-fact-along-with-do-until-group/18797/2 "2015-07-17T15:54:10Z")

</div>

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
