# Playbook Create File Based on Result of Previous Command

**URL:** <https://forum.ansible.com/t/playbook-create-file-based-on-result-of-previous-command/30516>\
**Category:** Ansible Project\
**Created:** [June 7, 2019, 9:30pm UTC](https://forum.ansible.com/t/playbook-create-file-based-on-result-of-previous-command/30516 "2019-06-07T21:30:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Douglas\_Thompson](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@Douglas\_Thompson](https://forum.ansible.com/u/Douglas_Thompson)\
**Post date:** [June 7, 2019, 9:30pm UTC](https://forum.ansible.com/t/playbook-create-file-based-on-result-of-previous-command/30516/1 "2019-06-07T21:30:05Z")

</div>

Hello,

I’m trying to run a command based on the result of a ‘yum update’ command on a Linux system. The idea being that if there are no patches, then I want to create a file that will be checked for just prior to a reboot. If the file exists, then no reboot, if the file doesn’t exist, reboot since yum update actually updated packages. Below is my current playbook, minus the reboot portion as I’m just in the testing phase.

I don’t get any errors, but my conditional statement isn’t seeing the string ‘Nothing to do’ and I know that is in the output of the yum update attempt.  
Anyone have any ideas?  
Thanks,

---

<div class="post-metadata">

**Author:** ![Douglas\_Thompson](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@Douglas\_Thompson](https://forum.ansible.com/u/Douglas_Thompson)\
**Post date:** [June 7, 2019, 9:48pm UTC](https://forum.ansible.com/t/playbook-create-file-based-on-result-of-previous-command/30516/2 "2019-06-07T21:48:47Z")

</div>

Of course the other option is to create the file if the value of update\_status.changed and update\_status.failed are both false, meaning nothing changed, but it didn’t fail. Either way, still can’t get it to see that those values are both ‘false’

–code

- name: create no\_patch file  
command: touch /tmp/no\_patch  
args:  
creates: /tmp/no\_patch  
when:
- update\_status.changed == “false,”
- update\_status.failed == “false,”

–output

ok: [[entrhelx01.oshkoshglobal.com](http://entrhelx01.oshkoshglobal.com)] =\> {  
“msg”: {  
“changed”: false,  
“failed”: false,  
“msg”: " Warning: Due to potential bad behaviour with rhnplugin and certificates, used slower repoquery calls instead of Yum API.",  
“rc”: 0,  
“results”: [  
“Nothing to do here, all packages are up to date”  
]  
}

---

<div class="post-metadata">

**Author:** ![Douglas\_Thompson](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@Douglas\_Thompson](https://forum.ansible.com/u/Douglas_Thompson)\
**Post date:** [June 11, 2019, 5:30pm UTC](https://forum.ansible.com/t/playbook-create-file-based-on-result-of-previous-command/30516/3 "2019-06-11T17:30:14Z")

</div>

Figured it out. the code should look like the following:

- name: create no\_patch file  
command: touch /tmp/no\_patch  
args:  
creates: /tmp/no\_patch  
when:

- update\_status.changed

- update\_status.failed
