Ansible dependencies for docker containers
I recently had the opportunity to test out Ansible's ability to interact with docker containers. Some might ask why we would want Ansible to connect to running containers. Afterall, we can build the containers to our liking using ansible-container, or even mundane tools such as Docker's Dockerfile. Also, we can link configuration files at runtime to override the container's settings where appropriate. The point, though, is to leverage Ansible's capability as an orchestration tool. As a very basic example, assume that you have plays for your non-docker environment to ensure MySQL users exist. How do you do that with Docker containers? You have a few options:
- Assume you have users with appropriate privileges that can connect remotely, you can execute the Ansible plays locally to connect to MySQL over the Docker network. You might need a few tweaks to the playbooks to connect remotely instead of locally and add module dependencies to your Ansible control machine.
- You might subscribe to the idea of running basic services such as SSH on your Docker containers, so Ansible would be able to connect just the same.
- If you run Ansible 2.0+, you can leverage Ansible's docker connection driver, adding to the list of existing drivers such as SSH, winrm, and paramiko.