I have a very simple Ansible playbook, all dependencies installed for docker-compose and docker but I get an error when installing docker-compose, this is the task on my playbook to install docker-compose in a CentOS7 environment.
#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
The following error appears:
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
I am kind of stuck with this simple error for a couple of hours. I got the command from standard docker site and tested directly in the shell and it works. I have also tried using double quotes to wrap around the command like command: "curl ..." but it didn't change the error.
Free Course: Introduction to DevOps Tools As mentioned, you can use Ansible to automate Docker and to build and deploy Docker containers. First, you'll need to have Docker SDK for Python installed.
As helloV
pointed out you need to use the shell
module if you want to utilise things like shell expansion or the shell's environment variables.
However, in Ansible you are typically better off using higher level modules and only resorting to the shell
or command
modules if you can't do what you need with another module. This approach gives you better control of execution for free such as easy idempotency and better output visibility.
In your case you can use get_url
(I believe Ansible will actually warn you if you attempt to shell out with curl that you might be better off with this module) to fetch things from the internet.
In your case your task might look something like this:
- 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'
The above task uses special variables that are returned by gathering facts on the targeted host so that your task should run fine on either Linux systems or OS X (you'd need a conditional suffix of .exe
for the Windows link to work and obviously a different destination path etc).
It also uses the mode
parameter from the file
module to add execution permissions for the user and group so you can avoid your chmod
task.
command
is not processed through a shell. Use 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With