【问题标题】:Ansible: curl from ansible playbook failed, but from the remote host itself successAnsible:来自ansible playbook的curl失败,但来自远程主机本身成功
【发布时间】:2019-11-11 13:54:36
【问题描述】:

我想在 ansible playbook 上做一些 curl,但总是失败。但是当我卷曲到远程主机本身时,它就成功了。

我试过了:

  1. 使用 ansible uri 模块
  2. shell 模块(原始 shell bash)
  3. 当前的一个是,我使用 shell 模块创建执行 curl 的可执行 .sh,然后执行它。

它们都不起作用。

这是我当前的代码:

- name: Write script to insert dummy data
  become_user: root
  shell: |
        echo "curl {{'http://localhost:8080/insetdummydata'}}" > "/home/ubuntu/insert.txt"

- name: Make script executable
  become_user: root
  shell: chmod +x /home/ubuntu/wildduck/insert.sh

- name: Execute script to insert dummy data
  become_user: root
  shell: /home/ubuntu/wildduck/insert.sh

输出应在控制台上打印响应,但由于状态连接被拒绝而失败。 Here is the error message

我在上面提到过,如果我在远程机器本身上进行 curl,则该命令有效。输出应打印请求的响应。 This is the output when i do the curl from remote host.

我在配置剧本时是否遗漏了什么?

【问题讨论】:

  • 请不要将文字作为图片发布。只需内联添加它。另外,这实际上是产生错误的剧本吗?使用 URL 作为变量的语法很奇怪。您能否将 shell 命令更改为仅 curl http://localhost:8080/insetdummydata 并使用 -vvv 发布 playbook run 的输出以进行调试输出?

标签: curl ansible


【解决方案1】:

要从网络服务器下载文件,请使用:

- name: Download foo.conf
  get_url:
    url: http://localhost:8080/insetdummydata
    dest: /home/ubuntu/insert.txt
    mode: '0440'

但是你能描述一下你想做什么而不是哪里出了问题吗?

【讨论】:

    猜你喜欢
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-06
    • 2020-03-28
    • 2017-09-29
    • 2015-11-17
    • 1970-01-01
    相关资源
    最近更新 更多