# Howto Trigger an action based on the result of a previous action and pull in data from a dictionary

**URL:** <https://forum.ansible.com/t/howto-trigger-an-action-based-on-the-result-of-a-previous-action-and-pull-in-data-from-a-dictionary/19342>\
**Category:** Ansible Project\
**Created:** [September 23, 2015, 3:34pm UTC](https://forum.ansible.com/t/howto-trigger-an-action-based-on-the-result-of-a-previous-action-and-pull-in-data-from-a-dictionary/19342 "2015-09-23T15:34:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris\_scott](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@chris\_scott](https://forum.ansible.com/u/chris_scott)\
**Post date:** [September 23, 2015, 3:34pm UTC](https://forum.ansible.com/t/howto-trigger-an-action-based-on-the-result-of-a-previous-action-and-pull-in-data-from-a-dictionary/19342/1 "2015-09-23T15:34:47Z")

</div>

Ok the scenario is I want to reset a users password on a system, but only if the user already exists. I cant find anyway to do this with existing modules, so I have reverted to a playbook. I’m not sure if my approach is fundamentally wrong but i can’t get it to work at the moment.

I use this sample dictionary. The accounts dont exist on the remote test system, so the idea is the adduser task doesn’t trigger. However if it did it would giving me the desired password reset.

# cat .userlist.yml

grps:  
crabtree: {}  
crabtree2: {}  
ut: {}  
uts: {}  
utsb: {}  
users:  
crabtree:  
comment: ‘’  
group: crabtree  
groups: crabtree,ut,uts,utsb  
name: crabtree  
password: $6$XaPMGsKF$1PThCIJDfpCbnWn/AB1uCox06k9ircsFJ8LFrCl1510E3toGJNmCye88PoEKLpxTrnpibKiGHsh0ff11apUWJ/  
crabtree2:  
comment: ‘’  
group: crabtree2  
groups: crabtree2,ut,uts,utsb  
name: crabtree2  
password: $6$2CMAcCiX$v2sFL5VKJ/HTVoRsGPpOju1/gJXQxjiC55CLVcngspUyLs3X2hWpdIF1igMrBECDo9OdU.vnvtNdG/MJzD1tH0

The following doesnt work as the variable structure doesnt really help

# cat //usr/local/scripts/ansible/playbooks/reset\_password2.yml

---

<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:** [September 23, 2015, 5:35pm UTC](https://forum.ansible.com/t/howto-trigger-an-action-based-on-the-result-of-a-previous-action-and-pull-in-data-from-a-dictionary/19342/2 "2015-09-23T17:35:51Z")

</div>

It might be easier to just run:

- getent: database=passwd

and then make the users conditional on:

- user: name=item.value.name state=present ...  
&nbsp;&nbsp;&nbsp;when: item.value.name in getent\_passwd

---

<div class="post-metadata">

**Author:** ![chris\_scott](https://avatars.discourse-cdn.com/v4/letter/c/ec9cab/32.png) [@chris\_scott](https://forum.ansible.com/u/chris_scott)\
**Post date:** [October 2, 2015, 7:53am UTC](https://forum.ansible.com/t/howto-trigger-an-action-based-on-the-result-of-a-previous-action-and-pull-in-data-from-a-dictionary/19342/3 "2015-10-02T07:53:40Z")

</div>

Finally got a chance to look at this again. Thanks for the pointer Brian you were spot on, and as a result its all far cleaner now.
