# Multiple test conditions for when: not working

**URL:** <https://forum.ansible.com/t/multiple-test-conditions-for-when-not-working/20938>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [March 21, 2016, 3:38am UTC](https://forum.ansible.com/t/multiple-test-conditions-for-when-not-working/20938 "2016-03-21T03:38:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew.graham](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@matthew.graham](https://forum.ansible.com/u/matthew.graham)\
**Post date:** [March 21, 2016, 3:38am UTC](https://forum.ansible.com/t/multiple-test-conditions-for-when-not-working/20938/1 "2016-03-21T03:38:57Z")

</div>

Hi All

I was running an apt\_update task and only wanted the server to reboot when it it saw neither of the two lines. Now, what is happening it only sees the first “test” I put in the when: section and ignores the second string to test. The reason for the two tests is I noticed that Debian and Ubuntu have different lines for when they have nothing to update.

I know Ive done something stupid…

- name: Run Apt update safe  
command: sudo apt\_upgrade\_safe  
register: apt\_update

- name: Reboot Server  
#command: sudo reboot  
command: echo “test”  
when: “‘0 to upgrade, 0 to newly install’ or ‘0 upgraded, 0 newly installed’ not in apt\_update.stdout”  
register: reboot

---

<div class="post-metadata">

**Author:** ![matthew.graham](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@matthew.graham](https://forum.ansible.com/u/matthew.graham)\
**Post date:** [March 21, 2016, 10:06am UTC](https://forum.ansible.com/t/multiple-test-conditions-for-when-not-working/20938/2 "2016-03-21T10:06:16Z")

</div>

I have also tried

“( ‘0 to upgrade, 0 to newly install’ not in ruby\_installed\_version.stdout) or ( ‘0 upgraded, 0 newly installed’ not in ruby\_installed\_version.stdout)”

maybe I missed something… or there is a better way to test for this… 😕

---

<div class="post-metadata">

**Author:** ![matthew.graham](https://avatars.discourse-cdn.com/v4/letter/m/c77e96/32.png) [@matthew.graham](https://forum.ansible.com/u/matthew.graham)\
**Post date:** [March 21, 2016, 9:51pm UTC](https://forum.ansible.com/t/multiple-test-conditions-for-when-not-working/20938/3 "2016-03-21T21:51:15Z")

</div>

This seemed to fix my issue but not sure if this is the way I should do it… any feedback would be lovely

when:

- (‘0 upgraded, 0 newly installed’ not in apt\_update.stdout)
- (‘0 to upgrade, 0 to newly install’ not in apt\_update.stdout)

---

<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:** [March 22, 2016, 9:33pm UTC](https://forum.ansible.com/t/multiple-test-conditions-for-when-not-working/20938/4 "2016-03-22T21:33:17Z")

</div>

seems like you wanted:

when: “( ‘0 to upgrade, 0 to newly install’ not in ruby\_installed\_version.stdout) and ( ‘0 upgraded, 0 newly installed’ not in ruby\_installed\_version.stdout)”

making them a list ( -) is an implicit AND.
