Management Node:
Remote Node:
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”)
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}}
result.stdout_lines is a string so tisDatabaseAge will be a string. Convert it to a int like this {{ 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")
Since tisDatabaseAge now is a int loose the quotes and it should work.
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)
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.
- name: GET AGE OF DATABASE ADS800DICE.S3DB ON SHARE
script: minutesSinceAccess.ps1 "{{uncServer}}"
"{{path/ADS800Dice.s3db}}" "seagate\{{userName}}" "password"
register: result
Add
- debug: var=result
- 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.
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)