【发布时间】:2020-06-16 15:57:20
【问题描述】:
我的 Ansible 任务在条件为假时失败(仅当“当”条件为真时,任务才会失败)
我的剧本
- 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
输出
"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
我的 when Condition 格式是否存在问题,因为我尝试了各种条件,例如 >0 和 >=1,但没有运气,因为它仍然失败(我的 ECS 集群中不存在任何任务)以及 AWS CLI 命令返回
aws ecs list-tasks --cluster mycluster --query length(taskArns[*])
0
【问题讨论】:
标签: ansible jinja2 amazon-ecs