In this article, I am going to show you how to configure a Kubernetes Cluster on AWS Cloud using Ansible.

Let’s Start

Step 1: Configure AWS CLI2 SDK


In this blog, I will demonstrate how I created an Ansible Playbook which will dynamically load the variable file named the same as the Operating System of the managed node, and just by using the variable names we can Configure our managed nodes.

Ansible Directory Structure.

Below is my directory structure for my ansible workspace:


In this blog, I will demonstrate how I used Ansible to perform the following operations:

  1. Configure Docker on Centos 8 or RedHat 8
  2. Start and enable Docker services
  3. Pull the Docker Image from GitHub
  4. Run the Docker container
  5. Use this new container as a managed host.
  6. Configure apache2 web server in the container managed host and expose it to the public.

Step 1: Create a workspace for ansible control node

$ mkdir ansible-ws

$ cd ansible-ws

$ mkdir inventorydb/

Create ansible.cfg file and add these values to it

$ vim ansible.cfg


In this blog, I will demonstrate how to perform the following operations:

  1. Create an AWS EC2 Instance.
  2. Configure the EC2 Instance with Apache Webserver and a PHP (PHP 7.2) application named “WordPress”.
  3. Configure AWS RDS to set up the MySQL database server (MySQL 5.7) for the WordPress application.
  4. Provide the endpoint/ connection string to the WordPress application to make it work.

Step 1: Create an AWS EC2 Instance.

AWS Management Console → EC2 → Instances → Launch Instances


In this blog, I will demonstrate how I created an Ansible Playbook and Ansible Role that can perform the following operations:

  1. myapache role to configure Httpd webserver.
  2. myloadbalancer role to configure HAProxy LB.
  3. Solving the challenge of Host IP addition dynamically over each managed node in hapoxy.cfg file.

Step 1: Ansible Configuration and Inventory files

$ vim ansible.cfg


In this blog, I will demonstrate how I created an Ansible Playbook that can perform the following operations:

  1. Configure the web servers on AWS EC2 Instances.

2. Configure the load balancer on AWS Instance.

3. Retrieve the IP Address of instances using the dynamic inventory concept.

4. The target nodes of the load balancer should auto-update as per the status of web servers.

Requirements:

  1. Ansible is configured on the Control Node.
  2. EC2 Instances for web servers should be running with Tag (Name: webservers)
  3. EC2 Instance for load balancer should be running with Tag (Name: loadbalancer)
  4. You should have an IAM…


Challenge:

Restarting HTTPD service is not idempotence in nature and also it consumes more resources. How can we rectify this challenge in Ansible Playbook???

Idempotency in Ansible

Ansible’s philosophy is that playbooks (whether for server provisioning, server orchestration, or application deployment) should be declarative. This means that writing a playbook does not require any knowledge of the current state of the server, only its desirable state.

The principle that enables Ansible to be declarative and yet reliable is idempotence, a concept borrowed from mathematics. An idempotent operation is one that can be applied multiple times without changing the result beyond the initial application, such…


Ansible is a software tool that provides simple but powerful automation for cross-platform computer support. It is primarily intended for IT professionals, who use it for application deployment, updates on workstations and servers, cloud provisioning, configuration management, intra-service orchestration, and nearly anything a systems administrator does on a weekly or daily basis. Ansible doesn’t depend on agent software and has no additional security infrastructure, so it’s easy to deploy.

Ansible seamlessly unites workflow orchestration with configuration management, provisioning, and application deployment in one easy-to-use and deploy platform.

Regardless of where you start with Ansible, you’ll find our simple, powerful and…


In this blog, I will demonstrate how I created an Ansible Playbook that can Install and configure a Hadoop HDFS Cluster using Ansible.

Ansible Playbook:

Inventory File:


Install and configure Docker and run a web server in the docker container.

In this blog, I will demonstrate how I created an Ansible Playbook that can perform the following operations:

  1. Configure Docker on Centos 8 or RedHat 8
  2. Start and enable Docker services
  3. Pull the httpd server image from the Docker Hub.
  4. Run the Docker container and expose it to the public
  5. Copy the HTML code in /var/www/html directory and start the webserver.

Now we can run the playbook:

$ ansible-playbook docker_conf_httpd_webserver.yml

Muhammad Tabish Khanday

Lets Code 💻

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