Ansible in the docker container?

Hi all,

Am I being too picky here or just being naive in the ways I approach my works with Docker? There are times when I build a Docker image and then when I run the container with some environment variables then my start/entry point scripts still have to replace some config files some where with the environment variables’ values. The most common practice for this type of situation is to use sed or some sort of shell capabilities to take care these. Honestly I hate going this way.

I wish I could just use Ansible for this type of situation but adding Ansible and dependencies to the container image increases the size and it is not ideal to have full Ansible functionalities in the container. So is it possible to create a core Ansible package aiming for the container situation that includes some of the base modules or at least just the base modules? Or do we have ways to assemble Ansible based on what the users might need to reduce size in the container?

Or just forget about it and add Ansible and its dependencies and call it a day…

Please point me to some documents or information if what I just asked have been written about.

Thank you so much.

You might want to take a look at Ansible Container:

https://github.com/ansible/ansible-container

Hi Greg,

I already use Ansible-Container but I believe that it is more for building the containers. The situations I have encountered are when I run the container and depending on the situations I might need to replace some variables here and there before starting the main process in the container. Currently, I’ve used sed to replace the values for these variables but that is not as powerful as using Ansible modules. Please correct me if I am wrong in the ways I use Ansible-Container or dealing with these situations when starting the containers.

Thank you,
Steven.

I faced the same thing, and I solved this by putting my config files or data in in a host directory and mounted this as a data volume (https://docs.docker.com/engine/tutorials/dockervolumes/).
I run Ansible from my desktop, run a playbook and template out or copy the necessary files to the server, in a host dir that is accessible for the Docker container.You can rebuild the container or just stop and start it again, to reread the files or configs.

The docker connection plugin is probably what you are looking for. It allows ansible to manipulate the container via the docker exec api.

I did try to reduce the size of Ansible and it is not worth it. I could only reduce around 4 MBs off the total size of the container.