Ansible Tower: Github Integration for Ansible Playbooks

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone scott with cyberscribe.org and in this video i'm going to be talking about using github to better integrate playbooks for ansible and ansible tower specifically ansible tower here and quick review what uh what the playbooks are for ansible are those are the yaml files that tell your ansible install like your controller node what to do to the managed nodes so maybe you have a playbook for example to update like here and this is these are the playbooks i'm talking about and just to say update and reboot after the update so these are the types of items that i'm going to be talking about integrating into ansible tower itself so github if you're not familiar is uh kind of a a platform for online platform for git it's free to people and you i mean there are enterprise licenses and and other licenses that you can pay for to get more features but it's really good free to anybody uh even private repositories meaning like not everybody can see it those are free too i think maybe up to a certain limit uh but it's a great space to kind of store your code and your other and you know other things that you just want to want to keep just you know not not on your own local computer but to have it kind of persistent uh in the cloud as they say so for this uh just a quick like review of version control which is what github is all about is it's basically allows multiple people or just one single person to collaborate on different types of code and just make changes review changes merge changes all about kind of changes like view changes from previously things like that so in this situation what we're going to be doing is i have this cyberscribe ansible github integration and i'll put a i'll put a link in the notes below for this and it should be open for everybody to access but what we're going to do is we're going to basically hook in this repository with these two yaml files these two playbooks i'm going to hook those into ansible tower itself so when ansible tower runs the playbooks it's not going to check its local system it's going to check this url here and then it's going to update them the playbooks uh before it runs there's multiple options and uh and yeah that's how that's how it's gonna we're gonna do it here it's a pretty good thing because once you if you have more than one person working on ansible playbooks it can kind of become difficult to if you're just working say you're sshing into your ansible server box it's kind of difficult if you think about it like if somebody makes a change how do you track that change how do you know what that person did what if that person really just messed up and uh you need to roll back how do you do that if it's just you know if they're just making changes on in a text editor on that machine itself not the easiest thing to do so here what you do is it's just all about uh you know you commit your changes and you uh you know you would push your changes to github itself and then what you would have is i don't have any commits here um but then you would just have these items here where you can go back and forth and see what people did and then you know kind of in case of emergencies you can go and roll back to what you had before you can see what people made what changes what specifically they did it's pretty good so this isn't a video about github or anything like that but just a quick uh minute or two about what the reason why we're doing this basically so going back to ansible tower what we're going to do is i'm just going to walk through setting up one of these and you can kind of follow along i'm also going to put the uh like i said the links and some notes some of my step-by-step items in the notes below so you can go through that too okay so let's get to it then we talked about git already and github which is what we're going to be pushing to so that's the first thing that you're going to do like i said this is going to be available for everybody but everybody's you know everybody's install is different and you're probably going to want to create your own say playbook repository and that's basically what these things are so i just have two security updates and it's just going to upgrade all packages that are just for security and you can look at the ansible notes for this too there's security right there and like i said in a previous video ansible documentation is pretty good so that is my one playbook and my other playbook is a bigger update so it just updates everything and it also reboots after 90 seconds giving a message of you know server is going to reboot because if you have for example like a kernel update you're going to need to reboot to have that take effect one other thing uh your host section is might be different remember this is the item in the inventory file that's uh that your ho that you can group your hosts under so unless you have rel hosts uh you might have to well you will have to change that unless you have rel hosts so just be aware i mean this is for uh you know for your just consumption but it's not you can't just copy and paste everything and just click a couple buttons i mean that's really not the point so anyway just be aware rel hosts is a group that i have in my inventory you want to make it work the same way put a rel hosts group in your inventory as well and uh and that's that so uh that's it for github itself so like i said for mine i have this as a public repository and you're probably not going to want to do that because you can't have these vanilla configurations all the time you're going to have to have your own things and specifically what you want to do so if and when you did that it would be a private repository and just a quick thing i'll put a link in the bottom for this too is you need to create a personal access token and that's how you would access uh your repository so how would you do that in github or how did how would you do that in ansible tower itself well basically what you would do is you would go to the credentials section here and then this is my deep dive sec github pat personal access token under source control so we can take a look at that uh it doesn't show passwords or anything but basically you would put something in here and how ansible tower is is it's if think about like object orientation where you kind of all of these things are little bits and you plug each of them into each other so you'll see this credential when we go through the templates to create the you know the the job to do to run the playbooks i will just hook this in i'm not going to now because it's public but that's how it would work if it was a private repository so like i said i'll put a link about the personal access tokens at the bottom too and you can take a look at that and uh just just go from there so getting into doing it on the ansible tower side first thing you'll need to do once you have those credentials set up and running is you'll need to create a project here and i'm just going to do do it live here and just say test project okay and then scm type so this is where you're going to hook it into github so scm type is get and let me get the url and scm url is right there and the branch commit if you look there main that d that's the default in github and get so main and just be aware that github is on top of git so get you can do by yourself you don't need github for that so they're two separate things but github uses git okay but we don't need to get too too deep into that all right so this is it organization it should populate i just have the default in there so this should be it for doing this basically your url and your branch name so we're going to save that and then we're going to go into templates and we're going to just kind of mirror this rel update that i have as you can see i've been testing this is over a couple weeks though so it's not like i was just constantly getting it wrong okay job template and the other thing is as we go through this some things i'm not going to just completely focus on how to do this how to do this because this is about just integrating github so you know other videos will come and uh about how to do some of these other other items basically uh so just be aware that's kind of we're focusing on the github integration for the playbooks here all right so we'll just say test template again and inventory this is going to be my test servers that i've set up before okay and project is going to be test project so that's kind of where we're hooking things in so if you look test project right that's where we i can't okay let me do this first choose a playbook now this should be integrated this should be connecting right here so i should see sec update and update right here and i do so that's good so if you put another uh you know if you put another this is the whole point of the github integration is if you put another playbook in here it's going to show up and then when you go through and you want to set up a schedule for this type of playbook you just do it this way and it and it should like i said add here okay so that keep in mind that's coming from github then what you want to do is verbosity normal doesn't really show you much it just basically shows you what ansible is doing so like ansible is running a job job starts long time job completes okay well what happened in between what if it's taking more time than you think it doesn't really tell you so there's a lot of verbosity options here i just go with one two is pretty good debug i think is if you put that on you'll just see just stuff endlessly scrolling uh so it's you know but i mean i think they're all worth testing out i'm just gonna go with verbose here and uh and that's it for that it'll just give a little bit more information but not be overwhelming credentials so this is kind of another topic for ansible tower about how to set up different credentials uh because you have to you know connect to your managed nodes so there's different ways of doing it i mean one would be to set up kind of public key authentication before this and you can probably do it in here i haven't looked too much but basically i'm just kind of doing it the the cheap way here of just using uh and not not good or anything by any imagination uh but just you know just basic connection like you know root so not good but that's not the point of this uh video and there's credentials is a big topic in ansible tower that's why that's why i'm kind of just glossing over it now because it's it would take some really diving into anyway we're connected to it right there uh choose a job type we're going to run so if you check it's going to basically do a dry run of the playbook but it's not going to do anything it'll just tell you if it would have worked or not so okay so you know like for example if you have a module an ansible module that tells says to do something on a program that doesn't exist on that box that you're trying to run it on you know that that check will tell you that like it you know doesn't exist things like that but we're not going to do that we're just going to run it and uh so here we're good to save and okay and we should be good to launch so there's a couple different places to launch it i mean really with ansible it's not about launching it ad hoc like this uh you can and that is uh useful but i think you know more it's more based on schedules here so basically what you can do is you can create a schedule think of this like cron and you know you can run it whenever you want start times things like that so this is what you'd probably want to take a look at as well i'm not going to do that here but just be aware that that's available so right now this was our test template and now we're as as you can see what you have a lot is with ansible tower you have like your detail on the top and on the bottom you have your uh kind of just summary i guess so that's basically what you're seeing here so let's just uh run this and see what happens and we have some verbosity so we can we can see if that's going to work so i already saved it and i can launch it here or i can just launch it test template right here so we're just gonna start let me just double check could i okay credentials inventory job tags this is good you know you can put well there's a place where you can put tags and then you can assign the tags here so that's uh that's good as well all right so we're just going to run a test template and we'll just see what happens okay so what we have update and reboot upgrade all packages here and see these are these little items that you're going to get that you wouldn't get if you didn't have the verbosity turned up so that's kind of nice and one thing here rebooting the servers so basically what that would be i think it already probably scrolled off for the uh for the other ones is these are my two servers that i'm managing here servo one servo two and basically what you'll see with the reboot is just wait for it and then you'll have your message coming up so i put that in the playbook for these things so i mean it's it's good to really like when you're starting out to have something where it kind of you can see that it's working especially like this update i did this earlier and it took like 13 minutes and i was thinking well this is dead but it wasn't dead it just took a while uh it was perfectly fine so uh you know just i mean that'll be experience and the more you do these things the more you'll get a an idea of how your environment is kind of set up to work so uh right there attention server will be rebooted in 90 seconds where did that come from well that came from the playbook right there and again the playbook was pulled from github and uh and that's it i mean it's rebooting the servers i don't think we need to wait for that but basically what i wanted to do here was to uh was to show you how to number one integrate into version control with github which we have that and uh you know set up playbook which is basically a template here and then as a job template and then just run it and show you that it was working and again like i said this is all from uh the playbooks here are all from github and those were from the projects which integrates into github itself and that specific repository there so with that you know kind of a backwards review of what we did but again i have notes and i'll put notes at the bottom of the video and that's all i had for this one so like i said i'll be other ansible tower topics i'll be kind of digging into a little more maybe providing some better ways to do things like credentials and uh and inventories and some other things so uh as i go through that stuff i'll be creating more videos and uh you know just stay tuned for those and that's all i had today so i will see you later
Info
Channel: CyberScribe.org
Views: 8,779
Rating: undefined out of 5
Keywords:
Id: IffmbIatwLk
Channel Id: undefined
Length: 18min 1sec (1081 seconds)
Published: Sat May 01 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.