Reputation: 569
Is it possible to bring 4-5 containers with docker-compose then run ansible roles?(Ansible can be installed onto one container or run from my local pc to a containers) So basically those 4-5 containers will be my target hosts.
Upvotes: 7
Views: 15192
Reputation: 4767
You can change the connection type of Ansible from SSH to Docker using ansible_connection: docker
in your inventory file or --connection docker
from the command line. This will allow you to use Docker hostnames as inventory. The documentation can be found here: https://docs.ansible.com/ansible/latest/plugins/connection.html
Upvotes: 7
Reputation: 311238
Sure, it's possible. You would target an image, not a container, by running Ansible as part of your Dockerfile. For example, something like:
FROM ubuntu:bionic
# Install prerequisities for Ansible
RUN apt-get update
RUN apt-get -y install python3 python3-nacl python3-pip libffi-dev
# Install ansible
RUN pip3 install ansible
# Copy your ansible configuration into the image
COPY my_ansible_project /ansible
# Run ansible to configure things
RUN ansible-playbook /ansible/playbook.yml
Note also that the packer tool can (a) build docker images and (b) has an ansible provisioner.
Upvotes: 7