ANSIBLE : Apache Web Server on DOCKER Container using Ansible
ANSIBLE
Ansible automates and simplifies repetitive, complex, and tedious operations. Everybody likes it because it brings huge time savings when we install packages or configure large numbers of servers.
Its architecture is simple and effective. It works by connecting to your nodes and pushing small programs to them. These programs make the system comply with a desired state, and, when they have finished their tasks, they are deleted.
Ansible works over SSH and doesn't require any daemons, special servers, or libraries to work. A text editor and a command line tool are usually enough to get your work done.
You simply describe your infrastructure in a text file (INI) and then all the information about the desired state of these machines are organized in playbooks. It is able to gather node information (such as IP addresses or Operating System details) into so-called "facts", which help with the selective and automated provisioning of different configurations on the platform. All of this with a language that is very human readable without the need to write code or declaring explicit relationships.
It uses the playbook to describe automation jobs, and playbook uses a very simple language YAML.
To Know more about ansible , check my this blog : ANSIBLE : How Industries are solving Challenges using Ansible
Ansible Playbooks and Ad Hoc Commands
Ad hoc commands can run a single, simple task against a set of targeted hosts as a one-time command. The real power of Ansible, however, is in learning how to use playbooks to run multiple, complex tasks against a set of targeted hosts in an easily repeatable manner. A play is an ordered set of tasks run against hosts selected from your inventory.
The playbook is the core component of any Ansible configuration.
An Ansible playbook contains one or multiple plays, each of which define the work to be done for a configuration on a managed server. Ansible plays are written in YAML. Every play is created by an administrator with environment-specific parameters for the target machines; there are no standard plays.
Ansible plays are flexible due to modules, which pertain to various aspects of the target managed servers. The module script written in Ruby. Modules exist for many parts of system configuration, including software installation and user management. Ansible, a RED HAT company, provides many modules, as does the open source community that uses and supports Ansible.
The playbook is therefore composed of plays, which are composed of modules. It executes when the administrator runs the ansible-playbook command against target machines. The administrator must use an inventory file to specify the hosts under the playbook's management.
INVENTORY FILE
DOCKER
But it’s not magic. Docker as a platform leverages containers – packages of an application along with all the tools it needs to run to eliminate differences between environments
Let's see how to Configure Apache Web Server on Docker Container using Ansible :
- Create folder for Mounting dvd
- Mount dvd
- Create yum repository
- Install docker-ce
- Install Docker SDK
- Start and enable docker services
- pull httpd server image from dockerhub
- run the docker container and expose it to the public
- copy the html code in /var/www/html and start webserver
Now this is the code written in YAML format in Playbook :
And this is my file written in simple HTML code that I copied using
copy module. File name - myweb.html
After running the playbook, you can see these outputs. Here you can
see no red colored output came up that means there's no error.
Here you can see, docker-ce has been installed.
We can check the service using "systemctl" command. Here for docker, it's started
Using "Docker images" command, you can check the list of images in docker. Here httpd image of latest version is present.
Using "docker ps" command, you can check the containers running in docker.
Here you can see, httpd image with image name - web1 is running on port number 8082.
To check if our code is working properly or now, we can check on
browser.
8082 as mentioned in playbook, we can check :
That means our webserver is working properly.
I hope now you have an idea about Ansible to get it started. Ansible is game changer in how you manage the infrastructure.
You can automate docker also using ansible. In one click, we can set up docker container and deploy httpd into it and start our webservice.
it's Amazing !!!!
Hope you liked my blog and it would be useful for you :)
Comments
Post a Comment