Question:
what I’m trying to accomplish is to run commands inside of a Docker container that has already been created on a Digital Ocean Ubuntu/Docker Droplet using Ansible.
Can’t seem to find anything on this, or I’m majorly missing something. This is my Ansible task in my play book. I’m very new to Ansible so any advice or wisdom would be greatly appreciated.
1 2 3 4 5 6 7 8 9 10 11 |
- name: Test Deploy hosts: [my-cluster-of-servers] tasks: - name: Go Into Docker Container And Run Multiple Commands docker: name: [container-name] image: [image-ive-created-container-with-on-server] state: present command: docker exec -it [container-name] bash |
Answer:
You should be able to execute a script (with your sequence of command in it) with docker exec
:
1 2 |
docker exec container-name bash -l -c /path/to/script > /path/to/log |
/path/to/script
should be accessible by your Ansible process./path/to/log
is a path inside the container, that could be shared in a volume.