Execute curl -X with ansible playbook

為{幸葍}努か 提交于 2019-12-03 11:01:39

问题


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

How can I run it?

If I run:

- 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"

I have the next fail:

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"}


回答1:


The best way to do this is to use the 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"

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'


来源:https://stackoverflow.com/questions/35798101/execute-curl-x-with-ansible-playbook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!