Active-Active Infrastructure using Terraform and Jenkins on Microsoft Azure

In this blog, we will create an active-active infrastructure on Microsoft Azure using Terraform and Jenkins.

Prime Reasons to have an active-active set-up of your infrastructure

Disaster Recovery:

Disaster recovery (DR) is an organization’s method of regaining access and functionality to its IT infrastructure after events like a natural disaster, cyber attack, or even business disruptions just like during the COVID-19 pandemic.

  • Ensure business resilience
    No matter what happens, a good DR plan can ensure that the business can return to full operations rapidly, without losing data or transactions.
  • Maintain competitiveness
    Loyalty is rare and when a business goes offline, customers turn to competitors to get the goods or services they require. A DR plan prevents this.
  • Avoid data loss
    The longer a business’s systems are down, the greater the risk that data will be lost. A robust DR plan minimizes this risk.
  • Maintain reputation
    A business that has trouble resuming operations after an outage can suffer brand damage. For that reason, a solid DR plan is critical.
Continue reading “Active-Active Infrastructure using Terraform and Jenkins on Microsoft Azure”

Increasing Code Reusability Using Task Groups in Azure DevOps

Let’s assume a scenario in which you are repeating a few tasks from your pipeline into multiple stages and/or pipelines or projects. In that case, it gets really tiring to repeat and configure each task individually over and over again. Azure DevOps provides the feature of Task Group in which we can encapsulate a sequence of tasks from our build or release pipelines and reuse those tasks in other pipelines.

What is Azure DevOps?

Now, let’s talk about Azure DevOps, it is a mixture of the simplest technologies and best practices. Therefore we can go as far as saying that it is the Next Big Thing in the IT Industry. Azure DevOps is a Software as a service (SaaS) platform from Microsoft providing an end-to-end DevOps toolchain for developing and deploying software. Microsoft launched this as they understood the fact that DevOps has become vital to a team’s success.

Task Group

task group facilitates the encapsulation of a sequence of tasks, defined already in a build or a release pipeline, into a single reusable task that can be added to a build or release pipeline (like any other task). We can, as per our choice, extract parameters from the encapsulated tasks as configuration variables, and abstract the rest of the task information.

The new task group is automatically added to the task catalog, ready to be added to other releases and build pipelines. At the project level, the task groups are stored and are not accessible outside the project scope.

Continue reading “Increasing Code Reusability Using Task Groups in Azure DevOps”

An Overview of Logic Apps with its Use Cases

See the source image

 

Azure Logic Apps is the PaaS (Platform as a Service) offering from Microsoft Azure. Logic Apps helps us to define workflows and build powerful solutions with the help of connectors, triggers, and actions.

 Prerequisites

– Basic understanding of cloud platform and SQL Query.

Let us understand this with a simple example:

Continue reading “An Overview of Logic Apps with its Use Cases”

Using Ansible Dynamic Inventory with Azure can save the day for you.

As a DevOps Engineer, I always love to make things simple and convenient by automating them. Automation can be done on many fronts like infrastructure, software, build and release etc.

Ansible is primarily a software configuration management tool which can also be used as an infrastructure provisioning tool.
One of the thing that I love about Ansible is its integration with different cloud providers. This integration makes things really loosely coupled, For ex:- we don’t require to manage whole information of cloud in Ansible (Like we don’t need instance metadata information for provisioning it).

Ansible Inventory

Ansible uses a term called inventory to refer to the set of systems or machines that our Ansible playbook or command work against. There are two ways to manage inventory:-
  • Static Inventory
  • Dynamic Inventory
By default, the static inventory is defined in /etc/ansible/hosts in which we provide information about the target system. In most of the cloud platform when the server gets reboot then it reassigns a new public address and again we have to update that in our static inventory, so this can’t be the lasting option.
Luckily Ansible supports the concept of dynamic inventory in which we have some python scripts and a .ini file through which we can provision machines dynamically without knowing its public or private address. Ansible Dynamic Inventory is fed by using external python scripts and .ini files provided by Ansible for cloud infrastructure platforms like Amazon, Azure, DigitalOcean, Rackspace.
In this blog, we will talk about how to configure dynamic inventory on the Azure Cloud Platform.

Ansible Dynamic Inventory on Azure

The first thing that always required to run anything is software and its dependencies. So let’s install the software and its dependencies first. First, we need the python modules of azure that we can install via pip.
 
$ pip install 'ansible[azure]'
After this, we need to download azure_rm.py

$ wget https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/azure_rm.py

Change the permission of file using chmod command.

$ chmod +x azure_rm.py

Then we have to log in to Azure account using azure-cli

$ az login
To sign in, use a web browser to open the page https://aka.ms/devicelogin and enter the code XXXXXXXXX to authenticate.

The az login command output will provide you a unique code which you have to enter in the webpage i.e.
https://aka.ms/devicelogin

As part of the best practice, we should always create an Active Directory for different services or apps to restrict privileges. Once you logged in Azure account you can create an Active Directory app for Ansible

$ az ad app create --password ThisIsTheAppPassword --display-name opstree-ansible --homepage ansible.opstree.com --identifier-uris ansible.opstree.com

Don’t forget to change your password ;). Note down the appID from the output of the above command.

Once the app is created, create a service principal to associate it with.

$ az ad sp create --id appID

Replace the appID with actual app id and copy the objectID from the output of the above command.
Now we just need the subscription id and tenant id, which we can get by a simple command

$ az account show

Note down the id and tenantID from the output of the above command.

Let’s assign a contributor role to service principal which is created above.

$ az role assignment create --assignee objectID --role contributor

Replace the objectID with the actual object id output.

All the azure side setup is done. Now we have to make some changes to your system.

Let’s start with creating an azure home directory

$ mkdir ~/.azure

In that directory, we have to create a credentials file

$ vim ~/.azure/credentials

[default]
subscription_id=id
client_id=appID
secret=ThisIsTheAppPassword
tenant=tenantID

Please replace the id, appID, password and tenantID with the above-noted things.

All set !!!! Now we can test it by below command

$ python ./azure_rm.py --list | jq

and the output should be like this:-

{
  "azure": [
    "ansibleMaster"
  ],
  "westeurope": [
    "ansibleMaster"
  ],
  "ansibleMasterNSG": [
    "ansibleMaster"
  ],
  "ansiblelab": [
    "ansibleMaster"
  ],
  "_meta": {
    "hostvars": {
      "ansibleMaster": {
        "powerstate": "running",
        "resource_group": "ansiblelab",
        "tags": {},
        "image": {
          "sku": "7.3",
          "publisher": "OpSTree",
          "version": "latest",
          "offer": "CentOS"
        },
        "public_ip_alloc_method": "Dynamic",
        "os_disk": {
          "operating_system_type": "Linux",
          "name": "osdisk_vD2UtEJhpV"
        },
        "provisioning_state": "Succeeded",
        "public_ip": "52.174.19.210",
        "public_ip_name": "masterPip",
        "private_ip": "192.168.1.4",
        "computer_name": "ansibleMaster",
        ...
      }
    }
  }
}

Now you are ready to use Ansible in Azure with dynamic inventory. Good Luck 🙂