How to Automate Infra setup in Azure Cloud using Ansible & AzureDevOps Pipeline | Ansible Automation

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back in this video we are going to learn how to automate infrastructure setup in Azure Cloud using ansible and Azure devops pipeline so let's take a simple use case let's say that you are working in a team they are completely into Azure Cloud they are moving away from on-premises into Azure Cloud so you have to create lot of resources in Azure cloud so of course right you have several options you can use terraform you can use ansible you can use Chef or puppet if you wanted to create resources in Azure Cloud you can also use Azure RM templates as well if you want to but let's say that your team is using ansible as a configuration management tool okay so using ansible they wanted to create resources in Azure Cloud so how you can automate that okay that's exactly what we are going to talk about in this short video okay so if you look at this diagram we are going to create ansible playbooks and we are going to commit those ansible playbooks in Azure post and then we are going to create Azure devops pipeline using this pipeline we are going to check out the code and then Azure devops pipeline will execute the ansible Playbook so that we can create resources in Azure Cloud so we are going to completely automate uh infrastructure Creation in Azure Cloud we are going to pick up a simple use case we are going to create something called Azure Resource Group in Azure Cloud we are going to just write a simple Playbook and then automate that maybe in upcoming videos we will talk about creating additional resources awesome so let's get started guys if you look at this diagram so let's just talk about how ansible can integrate with Azure Cloud right so the way ansible is going to first authenticate with Azure cloud is we are going to create something called service principle so using the service principle ansible will be able to authenticate with Azure cloud and then once it is authenticated we need to install something called Azure Aura modules so using the serger Aura modules ansible will be able to access Azure resources okay so that's the reason why if you look at the pipeline we are going to create these tasks in the pipeline we are going to create AML pipeline so we need to install ansible on the build agent because when you create Azure devops pipeline you can use either Azure hosted build legend or you can use a custom build agent but we are going to use Azure build agent so we need to install ansible on the build agent and then we also need to install ansible auto module on the build agent and then we are going to authenticate we are going to create maybe some pipeline variables which will which would contain a service principle value such as app ID subscription ID secret and whatnot and then we are going to create a resource Group in Azure Cloud right so we are going to completely automate all this task okay awesome so if you look at the prerequisite we need to have Azure account subscription okay and I am already connected to my Azure portal so this is the subscription I'm actually using so we'll be creating resources over here okay and we also need to create a service principle so using the service principle ansible will be able to authenticate with Azure Cloud so we are going to use Azure Cloud shell or you can also use Azure CLI in order to create a service principle but I'm going to use Azure Cloud cell in order to create the service principle okay and then once the service principle is created with a proper role and whatnot we are going to use those information in order to authenticate with Azure Cloud so we are going to create a pipeline variable with those information so we'll talk about that in a minute and then we need to create a ansible Playbook and then we are going to store those ansible uh you know playbooks in Azure reports and then we are going to create Azure devops pipeline uh we are going to create IML pipeline which is nothing but pipeline as a code and then of course with all these variables okay and then we are going to you know add these tasks so like I mentioned uh we are going to use one of the build agents I'm going to use Ubuntu build agent which is actually hosted in Azure cloud and we need to install ansible so this is how we are going to install ansible and then we also need to install Azure Aura modules as well and then of course whatever the Playbook we are creating which we are committing into Azure reports uh we are going to execute those playbooks over here and then of course by using this you know we will be able to authenticate and then once the pipeline is executed we should be able to verify that whether the resource Group has been created or not it's a very simple use case awesome guys so let's get started now uh let me start with creating a service principle uh it's very straightforward like I said you can use Azure Cloud shell or if you are already connected to your VM you can also use your Azure CLA as well to create a service principle or you can also use Azure portal as well to create a service principle uh so let me copy that code so let me copy this so I need to give a service principle name so I want to give ansible ASP means service principle okay I'm gonna say 23. okay and then we need to give a role for The Print Service principle so let me assign that role and then we also need to add our subscription right so and then subscription ID so I think I should be able to pick that up from here so that's my subscription ID so that's it right okay so this should take care of creating a service principle with this contributor role okay perfect let me execute that uh okay I have some issue there let me see I think I'm missing something oh you need to add doubles hyphen there yeah I have only single hyphen sorry about that awesome guys so the service principle got created and this also has the app ID and then this is the password and this is a tenant ID so we will be using these values shortly so let me go back to the instructions so yeah so we got created so we took care of this and then the next step would be we need to go ahead and then create ansible Playbook so what I'm going to do is um I'm actually going to go to my Azure devops dashboard so this is my Azure devops project and let me go to reports I have already created a repository here so I'm going to go ahead and then create ansible Playbook [Music] just so we took care of creating the service principle um The Next Step would be to go ahead and then create ansible Playbook so what I'm going to do is I'm going to go into my Azure devops dashboard so this is my Azure devops project I'm going to go into Repose so this is where we are going to create a ansible Playbook basically since this is just a demo right so what we are going to do we are going to create a simple playbook in order to create a resource Group in Azure Cloud so I have already written a small Playbook let me just copy this and let me go to repo uh let's just create a new file here new file so let me call this as create resourcegroup.aml create and then let me paste that code here let me fix this sorry about that so this is the resource Group name and then this is the location okay and then connection local means yes it is going to it is going to be executed on the build agent so that's what that means or whichever the machine is running right so it's going to use the local connection and click on Commit and then let me say uh create a Playbook for creating Resource Group in azure let me commit it there you go so we took care of creating a resource Group and then this is the resource Group name and this is a location perfect so let me go back to the instructions so we took care of creating a service principle we took care of creating ansible Playbook and then the next step would be to go ahead and then create a Azure AML Bill pipeline so let me go back to my Azure devops project dashboard here and then let me click on Pipeline so you can create a new pipeline click on new pipeline and like I said we are going to use pipeline as a code which is AML file so click on Azure post git and then click on the Repository and what I'm going to do is I want to start with the minimal pipeline code so let me click on starter pipeline so there you go so we were able to create the basic pipeline code here let me do some cleanup here okay so we need to start um you know adding task over here so like I said uh we we are going to have a task for you know performing these three activities right so we need to First install ansible on the build agent and then we need to install aurum ansible auto module and then we need to execute our Playbook okay so it's very uh simple so you can see the pipeline code here right so we want to of course if you want you can also copy and paste the entire pipeline code but I want to go step by step and I want to copy this particular command in order to install uh ansible on the build agent and then as you can see here Ubuntu is the build Legend right and of course we can also see that over here there you go okay so let me add my script over here and then here I want to say that uh install on build agent okay and then let's also go ahead and then add our next next task as well so let me just copy script here okay so the next step would be to go ahead and then install ansible Aura module so you just have to copy that put that over here okay and then let me add a display name here just to identify okay we're gonna say install ansible or module okay perfect so so far so good and let me go back to the pipeline code and then the next step would be to go ahead and then execute the Playbook but before that why don't I save the why don't I save the pipeline code and then try to run it okay so save save and run so let's see as you can see here it already installed ansible on the build agent and it also installed ansible Aura module as well on the build agent so so far so good if you go back and we can see here it executed all these tasks right so so far so good okay so the next step would be to go ahead and then execute our ansible Playbook so what I'm going to do is so let me go back here and the way we are going to execute our Playbook I think you all know that right you just have to say ansible playable and then provide the Playbook name and we can see our Playbook name here so this is the Playbook name copy that so I want to say executing the playbook in the agent to create Resource Group in Azure cloud s perfect so this should take care of executing the Playbook on the agent okay let me make sure everything is good everything is good so far and the last but not the least we also need to go ahead and then create pipeline variables so let's do that right now uh so the way you're gonna do that is go to variables click on new variable so we need to create all these variables right we need to create a variable called Azure subscription ID in fact we should have started with this first let me copy the Azure subscription ID can get that from here ok so yeah I think I would highly recommend to use this click on OK and then let me create let me save okay let me create one more I hope that got saved yeah it got saved and then the second variable is going to be Azure client ID that is actually nothing but app ID okay so put that over here a secret say okay and then let me add the next variable as your secret that is actually nothing but the password obviously we are going to select this say OK and the last variable which is nothing but the tenant ID so then we are going to store these say okay click on Save perfect and then we need to use those variables over here show the syntax everything is good okay perfect so that's it right so I'm going to click on save and then I'm going to say added pipeline variables click on Save so as soon as I save I'm pretty sure the pipeline is going to run and we can verify that over here there you go so let's see so as you can see here wow it also executed The Playbook as well let's see wow so look at here so this was able to execute the playbook for creating the resource Group so if I log into Azure Cloud so this is the resource Group it should have created right so let me go into Azure cloud go to home click on resource groups and then let me close this wow look at here guys right so that's the resource Group it has just created round and you can also see here few seconds ago the resource Group got created so yeah so that's it guys you know that's how you would be able to automate infrastructure setup on Azure Cloud using ansible and Azure devops pipeline thank you for watching this video folks
Info
Channel: DevOps Coach
Views: 1,484
Rating: undefined out of 5
Keywords:
Id: xx299QNUSvc
Channel Id: undefined
Length: 17min 32sec (1052 seconds)
Published: Sun Aug 27 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.