【问题标题】:translate curl PUT into ansible uri module将 curl PUT 翻译成 ansible uri 模块
【发布时间】:2015-03-18 00:05:42
【问题描述】:

我正在尝试使用 PUT REST 调用远程将 war 文件部署到 tomcat 管理器。我已经能够通过 curl 实现这一点,但我想遵循 ansible 最佳实践并在我的剧本中使用 uri 模块。

这是有效的 curl 命令。我在我的工作站上运行它:

curl -k -X PUT -u $TOMCAT_USER:$TOMCAT_PW --upload-file someapp.war "https://$SERVER:8443/manager/text/deploy?path=/someapp&update=true"

这是我尝试完成相同任务的任务(也在我的工作站上运行):

- name: Push war to Tomcat manager
  uri:
    url: "https://{{ inventory_hostname }}:8443/manager/text/deploy?path=/someapp&update=true"
    src: /opt/someapp.war
    user: "{{ tomcat_manager_username }}"
    password: "{{ tomcat_manager_password }}"
    force_basic_auth: yes
    method: PUT
  delegate_to: 127.0.0.1

ansible 任务以 OK 状态通过,但它推送的是一个空文件而不是 war。我认为您可以使用 src 参数替换 curl 中的 --upload-file 标志(因为 uri 模块使用文件模块中的所有参数)但显然情况并非如此。

有人能指出我在这里做错了什么吗?

ansible 版本:1.8.4

http://docs.ansible.com/uri_module.html

http://tomcat.apache.org/tomcat-8.0-doc/manager-howto.html#Deploy_A_New_Application_Archive_(WAR)_Remotely

【问题讨论】:

    标签: rest curl ansible


    【解决方案1】:

    URI Module 不以src 为参数。

    尝试使用 body 参数确保
    body="{{ lookup('file','/opt/someapp.war') }}

    【讨论】:

    • 它接受文件模块的所有参数,但我认为它对它们没有任何作用。尝试使用 body 并得到 Unexpected error in during lookup: 'utf8' codec can't decode byte 0xf5 in position 10: invalid start byte
    • 我很确定没有办法使用 URI 模块上传二进制文件。我最终只使用了带有 shell 模块的 curl 命令。
    • @KyleFrank 在完全相同的问题上苦苦挣扎,我现在得出了同样的结论:(
    • Ansible 目前不支持二进制文件上传
    猜你喜欢
    • 1970-01-01
    • 2023-02-04
    • 2021-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    • 1970-01-01
    相关资源
    最近更新 更多