# simple true/false statements in playbooks

**URL:** <https://forum.ansible.com/t/simple-true-false-statements-in-playbooks/22269>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [August 10, 2016, 9:31pm UTC](https://forum.ansible.com/t/simple-true-false-statements-in-playbooks/22269 "2016-08-10T21:31:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [August 10, 2016, 9:31pm UTC](https://forum.ansible.com/t/simple-true-false-statements-in-playbooks/22269/1 "2016-08-10T21:31:57Z")

</div>

Management Node:

- CentOs 7.1

- Ansible 2.1

Remote Node:

- Windows 7

- Powershell 3.0

I’m trying to display an error message if the file ADS800Dice.s3db has not been modified for more than an hour. The problem in in the last line. If I leave the quotes around the number 60, it gives me a false negative (evaluates to true when false). When I remove the quote around the number 60, it gives me a false positive (evaluates to false when true). I’d appreciate any help with this.

- name: GET AGE OF DATABASE ADS800DICE.S3DB ON SHARE  
script: minutesSinceAccess.ps1 “{{uncServer}}” “{{path}}/ADS800Dice.s3db” “seagate{{userName}}” “password”  
register: result
- set\_fact: tisDatabaseAge={{result.stdout\_lines.4}}
- name: CHECK AGE OF ADS800DICE.S3DB ON SHARE

debug: msg=“ERROR! ADS800DICE.S3DB HAS NOT BEEN UPDATED FOR {{tisDatabaseAge}} MINUTES.”  
when: (tisDatabaseAge \> “60”)

---

<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:** [August 10, 2016, 9:44pm UTC](https://forum.ansible.com/t/simple-true-false-statements-in-playbooks/22269/2 "2016-08-10T21:44:33Z")

</div>

> I'm trying to display an error message if the file ADS800Dice.s3db has not  
> been modified for more than an hour. The problem in in the last line. If  
> I leave the quotes around the number 60, it gives me a false negative  
> (evaluates to true when false). When I remove the quote around the number  
> 60, it gives me a false positive (evaluates to false when true). I'd  
> appreciate any help with this.
> 
> &nbsp;&nbsp;- name: GET AGE OF DATABASE ADS800DICE.S3DB ON SHARE  
> &nbsp;&nbsp;&nbsp;&nbsp;script: minutesSinceAccess.ps1 "{{uncServer}}"  
> "{{path}}/ADS800Dice.s3db" "seagate\{{userName}}" "password"  
> &nbsp;&nbsp;&nbsp;&nbsp;register: result  
> &nbsp;&nbsp;- set\_fact: tisDatabaseAge={{result.stdout\_lines.4}}

result.stdout\_lines is a string so tisDatabaseAge will be a string. Convert it to a int like this {{ result.stdout\_lines.4 | int }}

> &nbsp;&nbsp;- name: CHECK AGE OF ADS800DICE.S3DB ON SHARE  
> &nbsp;&nbsp;&nbsp;&nbsp;debug: msg="ERROR! ADS800DICE.S3DB HAS NOT BEEN UPDATED FOR  
> {{tisDatabaseAge}} MINUTES."  
> &nbsp;&nbsp;&nbsp;&nbsp;when: (tisDatabaseAge \> "60")

Since tisDatabaseAge now is a int loose the quotes and it should work.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [August 10, 2016, 10:26pm UTC](https://forum.ansible.com/t/simple-true-false-statements-in-playbooks/22269/3 "2016-08-10T22:26:01Z")

</div>

Thanks for the tip. But it is still evaluating as true when it should be false.

- name: GET AGE OF DATABASE ADS800DICE.S3DB ON SHARE  
script: minutesSinceAccess.ps1 “{{uncServer}}” “{{path/ADS800Dice.s3db}}” “seagate{{userName}}” “password”  
register: result
- set\_fact: tisDatabaseAge={{result.stdout\_lines.4|int}}
- name: CHECK AGE OF ADS800DICE.S3DB ON SHARE

debug: msg=“ERROR! ADS800DICE.S3DB HAS NOT BEEN UPDATED FOR {{tisDatabaseAge}} MINUTES.”  
when: (tisDatabaseAge \> 60)

---

<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:** [August 10, 2016, 10:40pm UTC](https://forum.ansible.com/t/simple-true-false-statements-in-playbooks/22269/4 "2016-08-10T22:40:23Z")

</div>

> Thanks for the tip. But it is still evaluating as true when it should be  
> false.

Then you need some debugging to see the content of the variable.

> &nbsp;&nbsp;- name: GET AGE OF DATABASE ADS800DICE.S3DB ON SHARE  
> &nbsp;&nbsp;&nbsp;&nbsp;script: minutesSinceAccess.ps1 "{{uncServer}}"  
> "{{path/ADS800Dice.s3db}}" "seagate\{{userName}}" "password"  
> &nbsp;&nbsp;&nbsp;&nbsp;register: result

Add  
&nbsp;&nbsp;&nbsp;- debug: var=result

> &nbsp;&nbsp;- set\_fact: tisDatabaseAge={{result.stdout\_lines.4|int}}

Add  
- debug: var=tisDatabaseAge

And run it again, this will give more clues of what's going on.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [August 11, 2016, 2:16pm UTC](https://forum.ansible.com/t/simple-true-false-statements-in-playbooks/22269/5 "2016-08-11T14:16:46Z")

</div>

Okay, it works now. Casting the variable as an int was key but I forgot the curly brackets around the variable name. Here is how the last line should be. Thanks Kai for your help!!

when: ({{tisDatabaseAge}} \> 60)
