本文介绍了使用Ansible Playbook执行curl -X的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用ansible剧本执行下一条命令:
I want to execute the next command using 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模块:
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模块:
Since your json file is on the remote machine the easiest way to execute is probably with the shell module:
- 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 Playbook执行curl -X的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!