Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run ansible in docker

Tags:

docker

ansible

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.

like image 978
Arsen Avatar asked May 08 '19 14:05

Arsen


1 Answers

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.

like image 125
larsks Avatar answered Oct 01 '22 03:10

larsks