我正在使用脚本模块在某些主机上运行脚本。我有一个数组ansible变量,我想将脚本作为空格分隔的参数传递。直接传递数组变量作为参数没有帮助。建议?
答案 0 :(得分:0)
您可以使用jinja filter加入您的列表,并将其作为变量传递,如下所示:
ansible -m script -a "myscript.sh {{ test_list|join(' ') }}" localhost -e "{"test_list": [1,2,3]}"
如果myscript.sh是:
#!/bin/bash
echo Args are: ${@}, 1st: $1 2nd: $2, 3d: $3
输出将是:
localhost | SUCCESS => {
"changed": true,
"failed": false,
"rc": 0,
"stderr": "",
"stdout": "Args are: 1 2 3, 1st: 1 2nd: 2, 3d: 3\n",
"stdout_lines": [
"Args are: 1 2 3, 1st: 1 2nd: 2, 3d: 3"
]
}