基本剧本是:
- name: "The Playbook"
hosts: "localhost"
tasks:
- name: "Get JSON from API"
uri:
url: "https://my.real.api.url.goes.here.com"
method: GET
return_content: yes
headers:
Content-Type: "application/json"
Authorization: "my api token goes here and works."
register: result
- name: Run Py script
command: python get_tenants.py {{ result }}
become: yes
become_user: root
register: pyout
我也试过传递结果:
{{ result | map(attribute='content') }}
我也试过传递结果:
{{ result | map(attribute='content') | list }}
不管怎样,我得到:
"failed": true, "msg": "[Errno 7] Argument list too long", "rc": 7
如何将ansible的一个大型JSON结果传递到python脚本中?
我的第一个想法是将结果保存到文件中,然后在python脚本中使用该文件。然而,在我看来,必须有更好的方法。。。