gro*_*roo 6 ansible docker ansible-playbook docker-compose
我有一个非常简单的Ansible playbook,为docker-compose和docker安装了所有依赖项,但是在安装docker-compose时遇到错误,这是我的playbook上安装docker-compose在CentOS7环境中的任务.
#ensure docker-compose and chmod +x /usr/local/bin/docker-compose
- name: Ensure docker-compose is installed and available
command: curl -L https://github.com/docker/compose/releases/download/1.7.0-rc1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
- name: Ensure permissions docker-compose
command: chmod +x /usr/local/bin/docker-compose
Run Code Online (Sandbox Code Playgroud)
出现以下错误:
TASK: [Ensure docker-compose is installed and available] **********************
failed: [nutrilife-aws] => {"changed": true, "cmd": ["curl", "-L", "https://github.com/docker/compose/releases/download/1.7.0-rc1/docker-compose-`uname", "-s`-`uname", "-m`", ">", "/usr/local/bin/docker-compose"], "delta": "0:00:00.004592", "end": "2016-03-26 14:19:41.852780", "rc": 2, "start": "2016-03-26 14:19:41.848188", "warnings": ["Consider using get_url module rather than running curl"]}
stderr: curl: option -s`-`uname: is unknown
curl: try 'curl --help' or 'curl --manual' for more information
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/home/mmaia/playbook.retry
nutrilife-aws : ok=4 changed=0 unreachable=0 failed=1
Run Code Online (Sandbox Code Playgroud)
我有点困惑这个简单的错误几个小时.我从标准的docker站点获得了命令并直接在shell中进行了测试并且它可以工作.我也尝试使用双引号来包围命令,如命令:"curl ..."但它没有改变错误.
yda*_*coR 19
如前所述,如果要利用shell扩展或shell的环境变量等内容,则需要使用该模块.helloV
shell
但是,在Ansible中,通常最好使用更高级别的模块,如果不能使用其他模块执行所需操作,则只能使用shell
或command
模块.这种方法可以让您更好地控制执行,例如简单的幂等性和更好的输出可见性.
在你的情况下,你可以使用get_url
(我相信Ansible实际上会警告你,如果你试图通过curl来解决你可能会更好的使用这个模块)从互联网上取东西.
在您的情况下,您的任务可能如下所示:
- name: Ensure docker-compose is installed and available
get_url:
url : https://github.com/docker/compose/releases/download/1.7.0-rc1/docker-compose-{{ ansible_system }}-{{ ansible_userspace_architecture }}
dest: /usr/local/bin/docker-compose
mode: 'u+x,g+x'
Run Code Online (Sandbox Code Playgroud)
上面的任务使用通过在目标主机上收集事实返回的特殊变量,以便您的任务在Linux系统或OS X上运行正常(您需要一个条件后缀,.exe
以便Windows链接工作,显然是一个不同的目标路径等).
它还使用模块中的mode
参数file
为用户和组添加执行权限,以便您可以避免chmod
任务.
command
不是通过shell处理的.使用shell
.
- name: Ensure docker-compose is installed and available
shell: curl -L https://github.com/docker/compose/releases/download/1.7.0-rc1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2727 次 |
最近记录: |