๐€๐ง๐ฌ๐ข๐›๐ฅ๐ž ๐๐ฅ๐š๐ฒ๐›๐จ๐จ๐ค ๐ญ๐จ ๐‚๐จ๐ง๐Ÿ๐ข๐ ๐ฎ๐ซ๐ž ๐€๐ฉ๐š๐œ๐ก๐ž ๐–๐ž๐›๐ฌ๐ž๐ซ๐ฏ๐ž๐ซ ๐จ๐ง ๐ƒ๐จ๐œ๐ค๐ž๐ซ ๐‚๐จ๐ง๐ญ๐š๐ข๐ง๐ž๐ซ

Parth Patel
4 min readMar 23, 2021
Ansible With Docker and Apache

Lets Understand some basics about Ansible and Ansible Playbook

To know more visit HOW ANSIBLE BENEFITS COMPANIES TO AUTOMATE

What is Ansible?

Ansible is an open-source IT Configuration Management, Deployment & Orchestration tool. It aims to provide large productivity gains to a wide variety of automation challenges.

What is Ansible Playbook?

Ansible Playbooks is the way of sending commands to remote systems through scripts. Ansible playbooks are used to configure complex system environments to increase flexibility by executing a script to one or more systems. Ansible playbooks tend to be more of a configuration language than a programming language.

Ansible playbook commands use YAML format, so there is not much syntax needed, but indentation must be respected. Like the name is saying, a playbook is a collection of plays. Through a playbook, you can designate specific roles to some hosts and other roles to other hosts. By doing so, you can orchestrate multiple servers in very diverse scenarios, all in one playbook.

What is Docker ?

Docker is an open platform for developing, shipping, and running applications by using containers. Docker enables us to separate our applications from our infrastructure so we can deliver software quickly. With Docker, we can manage our infrastructure in the same ways as we manage our applications. So, by taking advantage of Dockerโ€™s methodologies for shipping, testing, and deploying code quickly, we can significantly reduce the delay between writing code and running it in production.

What are Containers ?

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.

What is Apache Webserver ?

Apache HTTP Server is a free and open-source web server that delivers web content through the internet. It is commonly referred to as Apache and after development, it quickly became the most popular HTTP client on the web

Lets Start With Practical ,

Note, You Should have yum configured in your managed node.

Step 1: Firstly Install Ansible in your Control Node by using command pip3 install ansible

Step 2: Now, We have to setup inventory with Ip address, Username and Password of the Target Nodes.

so make inventory.txt with details in Control Node

Step 3: Now Go to Ansible Configuration File and Give the Path of your inventory File

In My Case I will Be using Local Host Instead of another Target Node

Step 4: Now, Lets make the Playbook with AnsibleDocker1.yml extension and write the yaml code

Here, I have configured yum repository for docker file, installed it and Started

Step 5: To use Docker through Ansible we need docker sdk installed through Python

So we first Install Python3 and the install Docker SDK using pip3 command.

Step 6: Now, Lets Pull or Download some Httpd image from Docker Hub so that we can launch or create an httpd container.

Here, I have also created /var/www/html directory and created a file index.html with some html code so that we can copy this in the container.

Step 7: Now, We have to launch Docker Container from httpd image and also expose the image to the public world so that they can visit the WebServer

I have also stopped firewall so any port can get to the target node.You can also enable the specific port if you want.

just run the playbook using command : ansible-playbook AnsibleDocker1.yml

this will automatically configure docker container with httpd image and launch the WebServer.

You can Visit webserver by: targetNodeIp:3036

Thank you for reading my article๐Ÿค—

Keep Learning๐Ÿ’ซKeep Sharing๐Ÿค๐Ÿป

Linkedin Profile :-

Do clap if this article was helpful. Good Day!

--

--

Parth Patel

ARTH Learner | Bigdata โ€” Hadoop | Linux | Front-End Developer | Flask | Coding Enthusiast | Python | AWS | Ansible | Kubernetes