python - 如何在ansible中打印python请求响应
问题描述
嗨,我正在使用 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)
解决方案
推荐阅读
- prometheus - 将 Prometheus PushGateway 与 OpenCensus Java 客户端一起使用
- python - 如何修复单击按钮但在第一次迭代后产生'ElementClickInterceptedException:'的while循环
- node.js - 如何在 prisma-binding npm 中获取总匹配记录数
- visual-studio - 当测试类派生自抽象基测试类时,如何使测试名称唯一
- java - 如何一次旋转一个字符?
- node.js - 如何在 mongodb 中使用 $lookup 从该表中获取与另一个表连接的数据
- firebase - 应用程序卡在启动屏幕上,然后显示错误“不存在捆绑 URL”
- java - 从 Eclipse 插件处理程序运行 java 程序
- database - Delphi SOAP 服务 - 与 Oracle 数据库的多个连接的问题
- sql-server - 如何获取 SSMS 的调试符号?(首选 17.9.1)