我正在尝试启动awx / tower作业模板,该模板传递变量中的值列表,但是该任务仅在一个目标主机上执行。
样品申请
curl -H "Content-Type: application/json" -X POST -s -u admin:admin123 -d '{ "extra_vars": { "domain": "dom-cn-1", "targets": "dev-cn-c1", "targets": "dev-cn-c2", "fwcmd": "fw sam -v -J src 192.168.10.10" }}' -k https://172.16.102.4/api/v2/job_templates/10/launch/
以上命令未按预期执行,而是在单个主机上运行。但是,当我通过cli运行同一本剧本时,这可以按预期工作。
domain: dom-cn-1
targets:
- dev-cn-c1
- dev-cn-c2
- name: "Create output file"
check_point_mgmt:
command: run-script
parameters:
script-name: "Create output file"
script: "fw sam -v -J src 192.168.10.10"
targets: "{{ targets }}"
session-data: "{{login_response}}"
答案 0 :(得分:0)
让我们在curl命令中提取json:
{
"extra_vars": {
"domain": "dom-cn-1",
"targets": "dev-cn-c1",
"targets": "dev-cn-c2",
"fwcmd": "fw sam -v -J src 192.168.10.10"
}
}
您不是在传递列表,而是两次使用不同值的相同参数。您必须像这样更正json:
{
"extra_vars": {
"domain": "dom-cn-1",
"targets": ["dev-cn-c1", "dev-cn-c2"],
"fwcmd": "fw sam -v -J src 192.168.10.10"
}
}