Configure Docker Using Ansible on AWS Part-1.

Arpita Srivastava
Sep 21, 2020 · 3 min read
Image for post
Image for post

Ansible is a configuration management system written in Python using a declarative markup language to describe configurations. It is used to automate the software configuration and deployment.

AWS (Amazon Web Services) is a comprehensive, evolving cloud computing platform provided by Amazon that includes a mixture of infrastructure as a service (IaaS), platform as a service (PaaS) and packaged software as a service (SaaS) offerings.

To know more about AWS visit my blog- Introduction to AWS.

Docker is a software for deployment automating and management of applications in a virtualization environment on the operating system level.

There are two Node(system) we are going to use:

  • Controller Node: from where we run our Ansible playbook.(In my case its my localhost)
  • Managed Node: where we configure the Docker.(and it will be AWS EC2)

Setup on Managed Node.

Image for post
Image for post
  • Enter its IP Address in the hosts file(inventory) at the controller node shown below.
  • Add rule in the security group: Protocol: ssh, Port: 22
Image for post
Image for post

That’s all in Managed Node side.

SetUp on Controller Node.

python3 --version
Image for post
Image for post

If not available then install python3 and ansible using yum command.

yum install python3
yum install ansible -y

To check ansible installed or not.

ansible --version
Image for post
Image for post

After Ansible is installed, we go to the home directory of Ansible i.e.,

cd /etc/ansible/
ls
Image for post
Image for post

You will see here a file named hosts, this file is known as default Inventory file. Here you can enter the lists of the Managed Node IP Address where you want to perform all the tasks.

Image for post
Image for post

You have to add few things in the Inventory file:

  • IP Address: Managed Node IP Address.
  • ansible_ssh_user: Username of the Managed Node.
  • ansible_ssh_pass: Password of the Managed Node.

Now finally we write the playbook:

  • Update the Managed Node
  • Install Python
  • Install Docker
  • Start Docker Service
  • Enable Docker Service
Image for post
Image for post

Now its time to run the playbook:

Image for post
Image for post
Image for post
Image for post

Here I have have attached the GitHub Repository link.

Bonus:Interview Questions.

  • Which module is used to enable and start the services?
  • What is the use of command module?
  • What is the difference between command, shell and raw modules?

If it is helpful, please give some claps, it encourage me write more. Thanks for reading.

In next part we look how to pull the image and run the container and configure the WebServer using Ansible.

Stay Tunned!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

DevTorq Community

Knowledge transforming careers

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store