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

如何在ansible中打印python请求响应,python,ansible,python-requests,Python,Ansible,Python Requests,您好,我正在使用ansible运行python脚本,它在从url获取数据后打印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 这是我的pytho

您好,我正在使用ansible运行python脚本,它在从url获取数据后打印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) 

首先将其存储到运行命令的任务中的某个寄存器。此外,仅根据您发布的内容,您可以使用ansible to,以及已经建议的有用的
寄存器: