Ansible剧本抱怨引号

时间:2019-12-15 15:17:48

标签: ansible yaml ansible-2.x

我正在将Ubuntu 16与Ansible 2.2.1.0一起使用。

我正在尝试将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'

出什么问题了?我有引号和结尾引号。

1 个答案:

答案 0 :(得分:0)

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角色,而不要重新使用轮子!