Creating ansible playbook for setting up apache webserver in a docker container.

Ishika Mandloi
3 min readNov 29, 2020

What is ansible?

Ansible is a simple IT automation engine that automates cloud provisioning, configuration management, application development, intra-service orchestration, and many other IT needs.

Ansible distribution have a controller node having ansible and number of manage nodes . Both controller node and manage node are connected through ssh. Using this distribution we complete same task parallel in every manage node, so that there is no waste of time.

What is ansible playbook?

Playbooks are the files where Ansible code is written. Playbooks are written in YAML format. Playbooks are one of the core features of Ansible and tell Ansible what to execute. They are like a to-do list for Ansible that contains a list of tasks.

For creating a distribution, we need only some details of managenode like ip, user name and password .

We need to create a file for details of manage node suppose ip.txt known as inventory.

And in ansible we have to create a configuration file

#mkdir /etc/ansible

#vim /etc/ansible/ansible.cfg

in this file we have to mention the file name having inventory.

Now we can start with our code….

Lets start!!!!!!!!!

We will be creating ansible playbook which will do following tasks:

● configure yum

● Configure Docker

● Start and enable Docker services

● Pull the httpd server image from the Docker Hub

● Run the docker container and expose it to the public

● Copy the html code in /var/www/html directory and start the web server

As Ansible playbook supports YAML format , we need to create an file with extension .yml and write following YAML code in it.

Here I have created myansibleplaybook.yml

To configure yum:

After completing playbook code, run command

#ansible-playbook <playbookname>

Now we can check on browser for the docker container ip , if it is showing my html code or not…

successfully completed our task!!!!

Really enjoyed learning ansible!!

Keep learning✌✌

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response