Last Updated on February 18, 2023 by cscontents
Introduction
Automation of platform building is one of the key areas which helps to bring production grade application live comparably must faster. And automation also enables reusability. So, it might be painful at the initial stage to develop the automated solution but in the long run you will be benefited.
When we speak about any web application, there are mainly two components –
- Infrastructure side – it means the servers, network etc. which will be used.
- Application side – it means the actual codebase (e.g., front-end, backend)
Note: In this article we will consider VM based application. You can apply the same idea for containerized application also.
Prerequisite
Before going through this article, I would assume you have good knowledge on the below tools –
If you want to learn Ansible basics then please check out the below course from KodeKloud which offers one of the best learning material in DevOps world.
Link of Training Course: Ansible for absolute beginners
Note: The above links are affiliate links, if you enroll this course using the above link, then it would help us to get some monetary benefit from KodeKloud. It won’t cost you anything.
Meaning of “Platform” in the current context
We know web application needs a platform to run on top of it. Here “platform” refers to that platform which is required to run an application.
Platform consist of below component –
- Infrastructure – it includes VM, container platform, network component, load balancers etc.
- Dependency software packages – once infra is ready we need to install the required dependency software packages which are required by the application.
Two major tasks in automation of Platform building
We just understood the main two component in platform. So accordingly, below are the two major tasks in making platform.
- Deploying Infrastructure – this can be automated using IaC (Infrastructure as Code) tool. The most popular tool is Terraform.
- Installing dependency software packages – this can be automated using Ansible. Though are other tools also, but here we are considering Ansible which is one of the most popular “IT Automation tool”.
Various ways to achieve complete automation of platform building
There are multiple ways through which we can achieve this. In the article we will see two such approach.
- Using Terraform for infra and ansible for dependency software installation. And Jenkins as a pipeline tool.
- Using ansible for both infra and dependency software installation. And Jenkins as a pipeline tool.
Using Terraform for infra and ansible for dependency software installation
Firstly, we need to have Terraform (IaC tool) codebase which will create the network component, VMs etc.
Here, main question how to inject Ansible script in Terraform code OR how we can integrate terraform & ansible to achieve complete platform automation.
One of the possible solution is using “provisioner” in terraform. We can place our Ansible scripts/ playbooks within the provisioner block in terraform.
Various types of provisioner in terraform –
- Local-exec – it can be used to run any script or execute any task locally.
- Remote-exec – it can be used to run any script or execute any task on the remote machine.
So here we would use “remote-exec” to install software packages on the newly created remote machines.
resource "aws_instance" "aws-test-vm" { ... instance_type = "t2.micro" . . . provisioner { ## ansible script comes here } }
And finally, we need to write a pipeline script in Jenkins which will fetch the Terraform & Ansible codebase from source code repository (e.g., GitHub) and run those scripts. We need to trigger the pipeline manually. This in only step which should be manual.
Using ansible for both infra and dependency software installation
Ansible is having plenty of modules using which we can automate tasks. So, we can use right ansible module to provision infra and to install dependency software packages.
For this we need to write ansible playbook and task should be placed in proper sequence. After writing ansible playbooks we need to push them in source code repository (e.g., GitHub) and as a pipeline tool we can use Jenkins.
Thank You.
If you are interested in learning DevOps, please have a look at the below articles, which will help you greatly.
- Kubernetes Series: Part 1 – Introduction to Kubernetes | Background of Kubernetes
- Kubernetes Series: Part 2 – Components of Kubernetes cluster | Kubernetes cluster in detail
- Kubernetes Series: Part 3 – What is Minikube and How to create a Kubernetes cluster (on Linux) using Minikube?
- Introduction to Ansible | High Level Understanding of Ansible
- Basics of automation using Ansible | Automate any task
- Automation of Java installation – using Ansible
- 10 frequently used ansible modules with example
- Jenkins Pipeline as code – High level information
- What is End-to-End Monitoring of any web application, and Why do we need it?
- What is “Monitoring” in DevOps? Why do we need to Monitor App/DB servers, Transactions etc.?
- DevOps Engineer or Software Developer Engineer which is better for you?- Let’s discuss
- How To Be A Good DevOps Engineer?
- How to do git push, git pull, git add, git commit etc. with Bitbucket