How to run Ansible playbook from Jenkins pipeline job | Ansible Jenkins Integration| DevOps Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everybody welcome back to ciao home in this example i want to demonstrate how to integrate ansible and jenkins we're gonna see how to execute ansible playbooks from jenkins using a plugin okay and we do this example using a pipeline job for the purpose of this demonstration i have jenkins and i have apache this is where i'm going to execute the ansible playbook all right and i do have a sample ansible project inside my github so we will go over this when we go and execute the code i say step 1 i want to install ansible on my jenkins box so i am trying to install ansible on amazon linux let me try with ansible 2. all right so we need to first enable uh epel after that let's give it try yes now our m repository is able to figure out ansible let's install it okay so that's step one and step two is let's install ants will plug in in jenkins i'm inside jenkins dashboard okay from jenkins home page click manage jenkins followed by manage plugins under available let's search for ansible plugin right so select this guy install without restart it got installed successfully let's go back and we need to configure the jenkins installation path under global tool configuration so click on manage jenkins global tool configuration so ansible give descriptor name so it could be any any name and the path to ansible executable folder we can get that from jenkins mission where ansible is installed see i should not copy that exe up to exe i should copy the folder where ansible executable is present then click save so next step would be let's create new job pipeline hit okay so let me put the script in line so once we are done with the script right i will keep it inside my repository and you guys can refer that so i am writing declarative pipeline in step one i want to clone my ansible repository so let's take help of pipeline syntax let's use git repository url because it's public repository i don't have to put the credentials it's getting failed because on my jenkins machine git is not installed all right let's make sure it is there now that error has gone get the pipeline script copy that so paste it here so that is step one and as a second step i want to execute ansible playbook so let's go to pipeline syntax so we installed ansible plugin we see that step visible in pipeline syntax generator the tool name we configured under global tool configuration ansible 2 playbook file path in workspace which is going to be apache dot yml so inventory file path in the workspace even inventory i have it part of my github project dev dot inv ssh connection credentials like when i execute this playbook it's going to execute on this group so inside inventory i have that group configure with one ip address now i need to provide ssh credentials for connecting to this machine with this user id and after connecting it's going to execute the playbook which installs apache web server there so add select jenkins ssh username with private key id username is ect user so i need to take the private key for connecting to my apache machine so that private key is used here you can check that app key which is sitting on my laptop okay so what i have to do now i need to uh select enter directly copy the private key content from my local file system put it here under my downloads app key dot bam let me open that with some editor take this so click add provide that key and say add again select that one so the executable file path is picked from here ansible to the playbook we want to execute the inventory file which contains manage node details and ssh credentials for connecting to manage node so these things i just want to leave default values [Music] even disable this host key checking otherwise it fails all looks good uh click generate pipeline script copy this go back and put it over there so when i execute this playbook it will clone this repository fine so on to our local jenkins workspace we will have these files right let me open apache.yaml uh it's going to install httpd it's going to start and enable that apache server and it's going to put index.html onto that apache server it's going to copy index.html from our local workspace it's here okay so go there save okay and build and wait for the output let's open console output it's cloning right and yes it's executing ansible playbook on web servers group it's successfully installed let me go back to our manage node take its public ip yes so the sample application deployed through ansible playbook is up and running that's all from this demonstration thanks for watching
Info
Channel: Java Home Cloud
Views: 31,185
Rating: 4.9329143 out of 5
Keywords: java home, devops, java home cloud, devops tutorial, devops by javahome, devops by java home cloud, ansible tutorial, jenkins pipeline tutorial, jenkins pipeline tutorial for beginners, running ansible from jenkins, running ansible playbook from jenkins pipeline jobs, integrating jenkins and ansible, ansible tutorial for beginners, how to integrate jenkins and ansible, ansible and jenkins pipeline, ansible jenkins plugin, ansible jenkins example, ansible jenkins pipeline example
Id: PRpEbFZi7nI
Channel Id: undefined
Length: 10min 45sec (645 seconds)
Published: Tue Jul 21 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.