【发布时间】:2020-11-13 08:59:49
【问题描述】:
我正在尝试使用 Python 从 REST API 运行 AWX 作业模板。仅在没有任何参数的情况下运行作业模板时它工作正常,但我需要在执行中指定目标主机。使用 get 方法时,我可以看到有一个“限制”参数。不幸的是,当我使用 python script.py job_id 运行代码时,我得到了 limit: b'{"job":2133,"ignored_fields":{"limit":"server-PRC-05"}," id":2133,"type":"job","url":" 等等。我找不到这个工作的例子。 请在下面找到我的python代码:
import sys
import requests
import json
templateid=sys.argv[1]
from requests.auth import HTTPBasicAuth
headers = {'content-type': 'application/json'}
data_new = {'limit': 'server-PRC-05'}
res = requests.post('http://awx_host/api/v2/job_templates/'+templateid+'/launch/',
verify=False, auth=HTTPBasicAuth('user', 'password'), data=json.dumps(data_new), headers=headers)
print (res.content)
【问题讨论】:
标签: python api rest ansible-awx ansible-tower