# Conditional when any of several tasks has been done

**URL:** <https://forum.ansible.com/t/conditional-when-any-of-several-tasks-has-been-done/23241>\
**Category:** Ansible Project\
**Created:** [December 12, 2016, 7:06pm UTC](https://forum.ansible.com/t/conditional-when-any-of-several-tasks-has-been-done/23241 "2016-12-12T19:06:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![John\_Oliver](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@John\_Oliver](https://forum.ansible.com/u/John_Oliver)\
**Post date:** [December 12, 2016, 7:06pm UTC](https://forum.ansible.com/t/conditional-when-any-of-several-tasks-has-been-done/23241/1 "2016-12-12T19:06:18Z")

</div>

Let’s say I have a playbook that looks for and changes lines in sshd\_config if necessary. Then I want the sshd service to be restarted only if at least one of those actions has taken place. Is there a way to evaluate for that without registering a variable for the completion of each and every play?

---

<div class="post-metadata">

**Author:** ![Spike\_Robinson](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@Spike\_Robinson](https://forum.ansible.com/u/Spike_Robinson)\
**Post date:** [December 12, 2016, 7:15pm UTC](https://forum.ansible.com/t/conditional-when-any-of-several-tasks-has-been-done/23241/2 "2016-12-12T19:15:37Z")

</div>

In the specific case of modifying one file only, multiple times, you could get away with one register for the original modification timestamp, and then compare that timestamp with the current timestamp as your last operation.  
In the general case, I think you need to use a register with a boolean for each operation that can trigger your final action.

---

<div class="post-metadata">

**Author:** ![John\_Oliver](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@John\_Oliver](https://forum.ansible.com/u/John_Oliver)\
**Post date:** [December 12, 2016, 7:50pm UTC](https://forum.ansible.com/t/conditional-when-any-of-several-tasks-has-been-done/23241/3 "2016-12-12T19:50:45Z")

</div>

Thanks, Spike. That’s what I’ll do. That, or a hash.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [December 12, 2016, 8:02pm UTC](https://forum.ansible.com/t/conditional-when-any-of-several-tasks-has-been-done/23241/4 "2016-12-12T20:02:06Z")

</div>

Check out handlers and notify.  
[https://docs.ansible.com/ansible/playbooks\_intro.html#handlers-running-operations-on-change](https://docs.ansible.com/ansible/playbooks_intro.html#handlers-running-operations-on-change)

---

<div class="post-metadata">

**Author:** ![John\_Oliver](https://avatars.discourse-cdn.com/v4/letter/j/97f17d/32.png) [@John\_Oliver](https://forum.ansible.com/u/John_Oliver)\
**Post date:** [December 12, 2016, 9:12pm UTC](https://forum.ansible.com/t/conditional-when-any-of-several-tasks-has-been-done/23241/5 "2016-12-12T21:12:47Z")

</div>

Darn it, I forgot all about handlers!
