I am getting a count from powershell command and registering it on variable. I have to use that count in when condition. I have changed it to int before using it in when condition too. Still that task ( mail notification) is getting skipped, eventhough the count is 0 here. Can someone tell me what I am doing wrong here. Below is the code I am executing
- name: Get message_count
shell: echo "{{ (output.stdout | from_json).MessageCount }}"
register: message_count #message_count is Zero here
delegate_to: localhost
- set_fact:
countt: "{{ message_count | int}}"
#tried converting to integer before passing to condition using set_fact
- debug: var=countt
- name: send mail notification
mail:
host: abc.zzzz.net
port: 25
from: <[email protected]>
to:
- [email protected]
subject: Test mail sent from core server
body: Test mail sent from core server
delegate_to: localhost
when: countt==0
here's what I did to make it work:
and here's the playbook run result:
so to recap:
{{ }}
inwhen
condition