1

我是编写ansible剧本的新手。我试图找到一种方法来检查是否传递了额外的参数。如果额外参数为空或未通过命令行传递,我想在控制台上输出错误消息。

我在这里尝试什么。

运行命令:-

$ ansible-playbook mytasks.yml -e "action=del"  

如果action为 null 或未通过,则应显示错误消息。

$ ansible-playbook mytasks.yml -e "action="  
$ ansible-playbook mytasks.yml

我的任务.yml

---
- hosts: local
  connection: local
  gather_facts: true

tasks:
- shell: echo "I've got '{{ action }}' and am not afraid to use it!"
  when: action is defined

- fail: msg="Bailing out. this play requires 'action'"
  when: action is not defined

我没有收到任何错误消息只是得到

TASK: [fail msg="Bailing out. this play requires {{action | mandatory}}"] *****
skipping: [localhost]

请建议我如何检查是否通过了额外的参数?

4

1 回答 1

0

您的代码在我的机器上运行良好。您使用的是什么 Ansible 版本?

于 2014-03-26T17:35:25.223 回答