如何在ansible中打印python请求响应

时间:2020-10-30 02:34:13

标签: python ansible python-requests

嗨,我正在使用ansible运行python脚本,该脚本在从网址获取数据后会打印json响应。 运行ansible任务后(在ansible输出中)如何查看json输出?

这是我的剧本

----
- name: Run on remote host
hosts: localhost

tasks:
 - name: run python script locally
command: python test.py -argument1 value -argument value

这是我的python脚本

import pprint
import requests
import base64

pat = ""
authorization = str(base64.b64encode(bytes(':'+pat, 'ascii')),   
'ascii')
url="https://dev.azure.com/{org}/_apis/projects?api-version=5.1"

headers = {
'Accept': 'application/json',
'Authorization': 'Basic '+authorization
}

response = requests.get(url, headers=headers)
if response.status_code == 200:
   print('Success!')
elif response.status_code == 404:
   print('Not Found.')
data = response.json()
pprint.pprint(data) 

0 个答案:

没有答案
相关问题