【问题标题】:Ansible playbook complains about quotesAnsible playbook 抱怨引用
【发布时间】:2020-04-08 05:51:31
【问题描述】:

我正在使用带有 Ansible 2.2.1.0 的 Ubuntu 16。

我正在尝试使用以下剧本安装docker-compose

  - name: Install Docker Compose.
      shell: "curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose"
      file:
         dest=/usr/local/bin/docker-compose mode=x
         src=/usr/local/bin/docker-compose  dest=/usr/bin/docker-compose state=link

我收到此错误:

  - name: Install Docker Compose.
      shell: "curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose"
           ^ here
This one looks easy to fix.  It seems that there is a value started
with a quote, and the YAML parser is expecting to see the line ended
with the same kind of quote.  For instance:

    when: "ok" in result.stdout

Could be written as:

   when: '"ok" in result.stdout'

有什么问题?我有开头和结尾的引号。

【问题讨论】:

  • Shell 是一个内置的 ansible 模块。所有模块在语法上都必须在名称下方准确对齐。这与 ansible、YAML 无关。它们是“报价”而不是配额!

标签: ansible yaml ansible-2.x


【解决方案1】:

shell 模块没有文件参数,并且 shell 和名称应该在同一列上,这就是你得到错误的原因,并且还对 URL 使用双引号而不是完整的 shell 命令:

   - name: Install Docker Compose.
     shell: curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose"

您可以使用get_url 模块将文件下载到目标并设置权限。我强烈建议使用 ansible galaxy 上的贡献者提供的 Ansible 角色,而不是重新邀请轮子!

【讨论】:

    猜你喜欢
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 2012-01-28
    • 2011-11-14
    相关资源
    最近更新 更多