Running Ansible playbook with Azure DevOps Pipelines

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello so in this tutorial i'll show you how to integrate ansible playbook with azure device pipeline so what we will do in this lab is we'll commit and playbook all right this playbook will basically install a web service on uh on any linux machine inside of your repo so we will push this playbook inside azure repo and this should trigger an azure pipeline and now your pipeline should talk to a self-posted agent where ansible would be installed okay and the playbook would be executed on this agent and once the playbook is executed it should configure our web server okay on the standalone linux machine it should configure web server based on the playbooks which we are trying to execute now for this demo you will require two virtual machine one is the ansible server and one additional virtual machine where ansible will basically execute playbook or any task which is written inside the playbook so i've already created two version machines one is the ansible server and another one is the web server okay both are sent to a7 and uh they are created offsite standard b1s which comes under free tier right so let's log into the ansible server okay first thing what i will do once i'm logged in is i'll install ansible and for installing ansible i'll run these commands i'll share the link to this commands in the description right so ensemble is installed you can check the version of the ansible by running ensemble iphone app converging command now next you will need to install git because uh on this uh this machine would be a self straight agent and it would be basically cloning the packages or the playbooks from the azure repo and it will require a git right so we'll install anything which is git dot above it so let's install gate okay so the gate is installed the next thing what you need to do is you would need to add this machine as a self-forced agent so i'll go to the azure devops project and inside project settings i'll go to agent pool and i'll go to default agent pool and i'll say add new agent and here you need to basically execute some stack on steps on your machine to basically install the vsts agent so let's download the vsts agent first so i'll say wget in the url which i just copied let's untie it okay and once you enter it you need to install certain dependencies okay now there's a folder known as dot bin and inside that there is a script known as install dependencies dot sh so you need to execute the script so it will install all the dependency required for this bsts agent all right so the dependencies are installed next you will run configure the message which will configure this agent okay i'll say yes the agreement then under server url you need to put your azure devops project url copy this and paste it over here then the authentication type is packed so i'll say yes to pat now let's create and personalize access token so i'll go to i'll click on this icon and then i'll go to personalize access token and i'll create a new token and we're creating it for the ansible host so i'll say ansible and i'll give it full access as of now and i'll create this token let's copy this token paste it over here okay so yeah there's other things you can leave default and so this installs the sorry this configures the agent now let's run the agent i'll run a script which is run dot fh and we'll run the script okay and once you run the script you go back to your agent pool you'll see one agent running named as ansible okay so the ansible is configured now next ansible will be communicating with this web server and for the web communication to happen and you would need to do some authentication so i'll generate an authentication key and i'll again run the agent with random message so i'll run the authentication i'll generate an ssh key i'll run a command with ssh keygen this will generate a new ssh key and then next you need to copy this key the copy i'll say ssh copy id and i'll copy this id to my web server so i'll just simply use the web server private ip address to copy the key let's say yes last for password of the web server so i'll enter the password and just copy the key so this key will basically ensure passwordless certain indications so if i say ssh the beer and the raid the api that's of the web server without any password i am logging into the web server now ansible would be able to log into web server without any password i'll say exit so i'll exit from the web server now now inside uh etc ansible right there is an inventory file okay so inside this inventory file i'll update the ip address of my web server okay so ansible knows to which target it is interacting with do a sudo seo and let's update it one more time so i'll say echo 10.1.0.5 okay and now if you run ansible hyphen m and let's say run a ping command on all the hosts in the inventory i should be able to ping my web server ansible is able to communicate with the web server now next task is to configure the pipeline so let's create a repo first okay so i'll create a new repo i'll call it as principal and inside this i'll create a new playbook is installing httpd so i'll say httpd.yml so this is my ansible playbook and the content of the playbook looks like this so what we are doing is we are running this playbook on all the hosts as to means becoming a root user and the task which i am running over here is to install httpd and php and making sure that the http services service is running so that's all this playbook is doing i'll commit the changes now let's go to pipeline and i'll go to release pipeline so i'll create a release pipeline for this ansible pencil configuration management i'll start with an empty job and i'll first add an artifact so artifact over here would be azure repo and the repo which we created which is ansible demo we'll use the main branch and now let's configure the stage i'll call it as ansible playbook stage so this will this is where we are running the ancient playbook and the agent i'll say that we are planning to use an uh self-hosted agent okay under the default pool and what we will run on this agent is an ansible task and simply execute the executioner task okay which is the run playbook and the file it will get the file from the artifact basically as you remove the artifact for my release pipeline which will get the edit from here and it will be using a default inventory file which is already present on the ansible server if you want you can give the list of file over here as inline configuration as well i'm not doing that because i we have already configured the ansible host file so that should work and i'll save this thing okay and let's enable continuous integration i'll just enable this trigger let's save this thing now let's do a small change we'll call it as i'll just put a text so that i can create a comment and uh this should basically trigger my pipeline we go to release pipeline it is rescued so anytime now you'll see it is going to a agent pool one of the agents in the agent pool that would be our ansible host okay so it's connected to agent now and here we go so it is downloading artifact and now finally running the playbook running the gathering effect step and now it is installing the service as well so install service starts which means that installing apache and php yes so the changes were successful which means the web server is installed so let's uh access our web server so i'll first enable uh i'll first name port 80. and now if i hit the i public ip address of my web server i should see a default apache page ideally okay so here we are so we are able to uh see the um page so this means ansible has executed the playbook on my web server and it was done through the as your pipeline so this is it for this tutorial i hope you like it do subscribe to the channel
Info
Channel: WebMagic Informatica - AWS, Azure, GCP & Devops
Views: 12,276
Rating: undefined out of 5
Keywords: Azure DevOps, Ansible
Id: yRPEJDcTxuk
Channel Id: undefined
Length: 12min 46sec (766 seconds)
Published: Tue Feb 01 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.