如何在Ansible CLI中将列表作为额外变量传递?

时间:2018-01-11 01:01:48

标签: ansible

是否有办法通过从CLI传递--extra-var / -e来覆盖Ansible变量。问题是我想要覆盖的变量是一个列表,我无法弄清楚正确的语法。

以下是我的group_vars文件中的变量:

my_variable:
    - { var1: "value1", var2: "value2" }
    ...

以下是我的命令:

ansible-playbook -i inventory playbook.yml -e 'my_variable={ var1: value1, var2: value2 }' --limit 1.2.3.4 --diff --check

我收到以下错误:

  

致命:[1.2.3.4] => with_items需要一个列表或一组

这可能吗?我做错了什么?

1 个答案:

答案 0 :(得分:1)

这是JSON,因此您需要将字典括在方括号中,以作为列表元素(JSON用语中的数组)传递。此外,您需要正确引用它:

<property name="dir" value="/path/to/dir" />

<!-- Set a property for consistency -->

<symlink action="delete" link="${dir}" />

<!-- If the file was a symlink, at this point it will be deleted. If it's a directory, nothing will have happened. -->

<delete dir="${dir.name}" />

<!-- If the file was a directory, it will now be deleted recursively. -->

<symlink resource="/path/to/some/other/dir" link="${dir}" />

<!-- Now the new symlink is created. -->
相关问题