[Ansible 版本 == 2.1.0]
为了运行目标服务器本地的脚本,我们可以使用 Ansible 的“命令”模块。以下可以轻松完成:
- name: Executing getpkgs.sh to download packages.
command: sh "/path/to /dir/scriptName.sh" arg1 arg2 arg3 arg4
我有我的脚本名称和存储在 ansible 变量中的参数。例如,以下变量包含所有脚本名称和要传递给这些脚本的参数:
scripts_to_execute:
- { filename: "/path/to/file/file1.sh", args: "arg11 arg12 arg13"}
- { filename: "/path/to/file/file2.sh", args: "arg21 arg22"}
- { filename: "/path/to/file/file3.sh", args: "arg31 arg32 arg33 arg34"}
我希望目标服务器上已经存在的所有这些文件都使用 with_items 执行。试图实现以下目标:
- name: Executing all files.
command: sh "{{item.filename}}" "{{item.args}}"
with_items: scripts_to_execute
我正在尝试传递脚本名称,后跟包含要传递到脚本中的所有参数的字符串。但它正在将那一串参数视为一个参数。