Execute ansible playbook on a docker container

0 votes
I'm trying to execute an ansible playbook on a docker container before running it on the actual platform(just to be safe). How do I do this? Can I please get a dockerfile for the same?
Jan 21, 2019 in Ansible by Ram

1 answer to this question.

+1 vote

Hey @Ram, you could use a dockerfile something like this:

# Start with the ubuntu image
FROM ubuntu
# Update apt cache
RUN apt-get -y update
# Install ansible dependencies
RUN apt-get install -y python-yaml

 # Set variables for ansible
WORKDIR /tmp/ansible
ENV PATH /tmp/ansible/bin:/sbin:/usr/sbin:/usr/bin
ENV ANSIBLE_LIBRARY /tmp/ansible/library

 # add playbooks to the image. This might be a git repo instead
ADD playbooks/ /etc/ansible/
ADD inventory /etc/ansible/hosts
WORKDIR /etc/ansible

 # Run ansible using the site.yml playbook
RUN ansible-playbook /etc/ansible/site.yml -c local
answered Jan 21, 2019 by Vedant

Related Questions In Ansible

0 votes
1 answer
0 votes
1 answer

Running a playbook using Ansible on Jenkins

Hey, @Asha seems like you've added a ...READ MORE

answered Apr 4, 2019 in Ansible by Akhil
0 votes
1 answer

How do I execute a shell script and then use the result in ansible

This can work out for you: - name: ...READ MORE

answered Apr 11, 2018 in Ansible by shubham
• 6,910 points
+1 vote
2 answers

Running ansible command on a single server when it is deployed to multiple servers

You can try the run_once attribute: Example from ...READ MORE

answered Jun 13, 2018 in Ansible by DareDev
• 6,850 points
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 57,530 points
0 votes
1 answer

Execute a command using ansible playbook

Hey @Reshma, You can use the URI ...READ MORE

answered Jan 17, 2019 in Ansible by Sameer
0 votes
1 answer

Ansible playbook to wget a file

Hey @Celia, one recommendation, try not using ...READ MORE

answered Jan 16, 2019 in Ansible by Vaishu