Ansible Integration with Docker by writing a Playbook and launching Containers in our Managed Node.

Ansible Integration with Docker by writing a Playbook and launching Containers in our Managed Node.

Server automation now plays an essential role in systems administration, due to the disposable nature of modern application environments. Configuration Management tools such as Ansible are typically used to streamline the process of automating server setup by establishing standard procedures for new servers while also reducing human error associated with manual setups.

Ansible offers a simple architecture that doesn’t require special software to be installed on nodes. It also provides a robust set of features and built-in modules which facilitate writing automation scripts.

No alt text provided for this image


Prerequisites

In order to execute the automated setup provided by the playbook , we’ll need:

  • One Ansible control node: an Ubuntu 18.04 machine with Ansible installed and configured to connect to your Ansible hosts using SSH keys. Make sure the control node has a regular user with sudo permissions and a firewall enabled.
  • One or more Ansible Hosts.
No alt text provided for this image


Ansible Playbook

Playbooks are the files where Ansible code is written. Playbooks are written in YAML format. YAML stands for Yet Another Markup Language. 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.

Playbooks contain the steps which the user wants to execute on a particular machine. Playbooks are run sequentially. Playbooks are the building blocks for all the use cases of Ansible.

No alt text provided for this image

Docker

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

No alt text provided for this image


So let's start with our task.


No alt text provided for this image
  • With a fresh installation of Ansible, like every other software, it ships with a default configuration file. This is the brain and the heart of Ansible, the file that governs the behavior of all interactions performed by the control node. In Ansible’s case that default configuration file is (ansible.cfg) located in /etc/ansible/ansible.cfg. The host file is used to store connections for Ansible playbooks.


No alt text provided for this image
  • This is my Managed Node. As you can see, Docker is not installed yet on the Managed Node. We will do it with the help of Ansible configured at Controller Node.


No alt text provided for this image
  • As you can see, my Yum is not configured as well. Before Installing Docker we need to configure Yum in our Managed Node as well. This will be also done with the help of Ansible.


No alt text provided for this image
  • We will go to our controller node and create a yml file. Let it be named as docker.yml


No alt text provided for this image
  • So we create a Playbook named as docker.yml where we will write our yml code for Yum configuration.


No alt text provided for this image
  • Save the Configuration file and run the command. Make sure the identation of yml file is correct otherwise it will give errors.


No alt text provided for this image
  • As you can see in my Managed Node yum is configured as well.


No alt text provided for this image
  • Now we need to install the docker. It is not yet installed in my Managed node.


No alt text provided for this image
  • After configuration of yum we can write a command of installation of Docker with nobest keyword. Ansible will do it for us.


No alt text provided for this image
  • As you can see , the installation is successful and changes has been done in my managed Node denoted by yellow text.


No alt text provided for this image
  • As you can see , the managed node now has Docker installed and ready to be used.


No alt text provided for this image
  • But the Docker services has not been started yet. So we will start it's services by writing a script in the Controller Node again.


No alt text provided for this image
  • So we start the services of Docker by writing the above script and assigning the state as started.


No alt text provided for this image
  • Changes has been done and let's check our Managed Node.


No alt text provided for this image
  • So Docker services has been started.


No alt text provided for this image
  • Now here's the main point of our task. We need to pull the ubuntu image. But we cannot do with the help of a python Library called PIP. But PIP also requires some Python software called Python36. So we first install Python36 and then pip. At last we pull the docker Image.


No alt text provided for this image
  • Changes has been Done and required softwares along with docker image has been pulled.


No alt text provided for this image
  • Here is my pip library on my managed node showing it has been successfully installed.


No alt text provided for this image
  • Here is my Docker image that has been downloaded successfully.


No alt text provided for this image
  • Now we will Launch our Container .


No alt text provided for this image
  • So the Container has been successfully launched.


No alt text provided for this image
  • And here it is!!!.

So our first task of Integration of Ansible with Docker has been Done.


要查看或添加评论,请登录

NIRBHAY MAITRA的更多文章

社区洞察

其他会员也浏览了