gpt4 book ai didi

ansible - 使用 ansible playbook 执行 curl -X

转载 作者:行者123 更新时间:2023-12-03 11:51:08 31 4
gpt4 key购买 nike

我想使用 ansible playbook 执行下一个命令:

curl -X POST -d@mesos-consul.json -H "Content-Type: application/json" http://marathon.service.consul:8080/v2/apps

我该如何运行它?

如果我运行:
- name: post to consul
uri:
url: http://marathon.service.consul:8080/v2/apps/
method: POST
body: "{{ lookup('file','mesos-consul.json') }}"
body_format: json
HEADER_Content-Type: "application/json"

我有下一个失败:
fatal: [172.16.8.231]: FAILED! => {"failed": true, "msg": "ERROR! the file_name '/home/ikerlan/Ik4-Data-Platform/ansible/playbooks/Z_PONER_EN_MARCHA/dns-consul/mesos-consul.j2' does not exist, or is not readable"}

最佳答案

最好的方法是使用 URI module :

tasks:
- name: post to consul
uri:
url: http://marathon.service.consul:8080/v2/apps/
method: POST
body: "{{ lookup('file','mesos-consul.json') }}"
body_format: json
headers:
Content-Type: "application/json"
由于您的 json 文件位于远程计算机上,因此最简单的执行方法可能是使用 shell 模块:
- name: post to consul
shell: 'curl -X POST -d@/full/path/to/mesos-consul.json -H "Content-Type: application/json" http://marathon.service.consul:8080/v2/apps'

关于ansible - 使用 ansible playbook 执行 curl -X,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35798101/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com