# notify on file existence?

**URL:** <https://forum.ansible.com/t/notify-on-file-existence/35575>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [August 2, 2021, 3:03pm UTC](https://forum.ansible.com/t/notify-on-file-existence/35575 "2021-08-02T15:03:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oloryn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/oloryn/32/7904_2.png) [@oloryn](https://forum.ansible.com/u/oloryn)\
**Post date:** [August 2, 2021, 3:03pm UTC](https://forum.ansible.com/t/notify-on-file-existence/35575/1 "2021-08-02T15:03:39Z")

</div>

I've got a playbook where a couple of tasks are notifying a 'Reboot server' handler when a lineinfile generates a change. I \*also\* want to notify the same handler when the reboot-required file exists (this is on Ubuntu). My brain is glitching as to how to get this done.

Essentially I have code:

---

<div class="post-metadata">

**Author:** ![oloryn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/oloryn/32/7904_2.png) [@oloryn](https://forum.ansible.com/u/oloryn)\
**Post date:** [August 2, 2021, 3:26pm UTC](https://forum.ansible.com/t/notify-on-file-existence/35575/2 "2021-08-02T15:26:54Z")

</div>

\<quote voice="Gilda Radnor"\>Never mind\</quote\>

A breather, a better specified Google, and I"ve found what I need.

Looks like what I want is more like this:

&nbsp;&nbsp;&nbsp;&nbsp;- name: check if a reboot is required  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;shell: "[-f /var/run/reboot-required]"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;failed\_when: False  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: reboot\_required  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;changed\_when: reboot\_required.rc == 0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;notify: reboot

Ben

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [August 2, 2021, 3:30pm UTC](https://forum.ansible.com/t/notify-on-file-existence/35575/3 "2021-08-02T15:30:57Z")

</div>

Though this is more efficient and easier to understand:

&nbsp;&nbsp;- name: Get reboot-required status  
&nbsp;&nbsp;&nbsp;&nbsp;stat: path=/var/run/reboot-required  
&nbsp;&nbsp;&nbsp;&nbsp;register: file\_reboot\_required  
&nbsp;&nbsp;&nbsp;&nbsp;changed\_when: file\_reboot\_required.stat.exists  
&nbsp;&nbsp;&nbsp;&nbsp;notify: reboot

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
