Ansible docker module missing CP command?

7k views Asked by At

The docker client offers the cp sub-command as explained here, which is very handy when one needs to copy a file into a container (note: this is somewhat analogous to Dockerfile ADD instruction in image building). In Docker 1.8 the cp command has been even expanded a bit.

However, reading the Ansible docker module documentation, it appears that this is missing? Here are my 2 questions:

  1. Did I misunderstand the Ansible documentation?
  2. if Ansible is missing the cp thing, has anyone found a workaround? I can think of something like using Ansible copy module to transport the files to the remote machine first, and then run there the native docker client with cp, but ideally Ansible's docker module would have done this in a single shot as part of the docker module?

Thanks in advance.

3

There are 3 answers

1
dshenoy On BEST ANSWER

You can also use the synchronize command ~ examples provided in this link:

http://opensolitude.com/2015/05/26/building-docker-images-with-ansible.html

4
hostmaster On
  1. You didn't. Ansible's docker module does not support copying files or folders from a container.
  2. There is no simple way to do so. I mean you need a hack. Off the top of my head you can play with '-' argument for docker cp option.

However from my point of view if you wish to copy something into a container you're probably doing something wrong. Containers should be ephemeral.

0
rokpoto.com On

Using ansible shell module helped:

  - name: copy db dump to localhost
    ansible.builtin.shell: docker cp container:/tmp/dump.sql /tmp/dump.sql