My Ansible Task is getting failed with false when condition ( Task should fail only if "when" condition is true)
My Playbook
- name: 'Check if any task is existing'
command: aws ecs list-tasks --cluster mycluster --query length(taskArns[*])
register: ecs_tasks
- name: 'Fail playbook if some task is already existing in cluster'
fail:
msg: "There is already an existing task in mycluster"
when: ecs_tasks.stdout != 0
- name: 'Create Ranger task'
command: create ECS task
register: ecs_task
Output
"stderr": "",
"stderr_lines": [],
"stdout": "0",
"stdout_lines": [
"0"
]
}
TASK [Fail playbook if some task is already existing in cluster] ***************
task path: /home/somepath/Task.yml:35
fatal: [127.0.0.1]: FAILED! => {
"changed": false,
"msg": "There is already an existing task in mycluster"
}
PLAY RECAP *********************************************************************
09:09:38 127.0.0.1 : ok=5 changed=4 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
Is it some issue with my when Condition format, because i have tried various conditions like >0 and >=1, but no luck as it is still failing for (No tasks exists in my ECS cluster) and also AWS CLI Command returns
aws ecs list-tasks --cluster mycluster --query length(taskArns[*])
0