本文介绍了使用 ansible playbook 执行 curl -X的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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"

我有下一个失败:

致命:[172.16.8.231]:失败!=>{"failed": true, "msg": "错误! file_name '/home/ikerlan/Ik4-Data-Platform/ansible/playbooks/Z_PONER_EN_MARCHA/dns-consul/mesos-consul.j2' 不存在,或不可读"}

推荐答案

最好的方法是使用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 21:53