python调用rundeck的webhook并向作业传递参数的简单实现

python脚本如下:

# -*- coding: utf-8 -*-
import json
import requests
content = '{"field1":"","field2":"","field3":""}'        #准备传递给rundeck作业的参数
payload = json.loads(content)
payload["field1"] = "192.168.8.8"                        #参数1         
payload["field2"] = "\"ls /tmp >> /tmp/testssss.txt\""   #参数2
payload["field3"] = "root"                               #参数3
headers = { 'Content-Type': 'application/json',}
url = "http://192.168.*.*:4440/api/35/webhook/*****rundeck类似于token的值#pwhok"
response = requests.request("POST", url, headers=headers, data = json.dumps(payload))
print(response.text.encode('utf8'))

rundeck Webhooks 的配置

python调用rundeck的webhook并向作业传递参数的简单实现_第1张图片

 

执行python脚本,即自动调用rundeck并传递参数

 

你可能感兴趣的:(python调用rundeck的webhook并向作业传递参数的简单实现)