Ansible Tower: Github Inventory Integration

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone scott with cyberscribe.org and in this ansible tower video i'm going to be integrating my ansible inventory into github so a quick review an inventory and an inventory file in ansible is the file that you use to declare your managed nodes so you know you want to control manage configure update backup whatever you do with ansible you want to do that on you know server one two three and four well the hosts files where you put server one two three and four and that's basically like that's the thing that tells ansible where to go to do its stuff so in a previous video i did an integration in github with ansible playbooks so this is kind of just an extension of that but here you're going to be doing the inventory integration and this is also helpful too again it's a single place where people can maybe more easily view it update it access it the inventory i'm talking about compared to just having like say a flat file in etsy ansible hosts or something so let's get started first thing you'll need to do is to create a hosts file in your github repository so here i'm not going to put my a link to it because it's private and i'm going to be changing this i'm going to be using this kind of for my own stuff as well which is why it's private but basically create your hosts file in your github repository and that's going to be the one that you are linking to ansible tower itself so here again pretty simple just working at least for the moment off uh you know all serve one two rel hosts red hat enterprise linux because i have a like a demo update playbook that i'll be using so that's what that's going to be for and and that and there's a lot more that you can do with hosts you can do ips you can do ip ranges you can do all kinds of stuff not just host names but really it's at the end of the day it's to declare your man managed nodes so create your hosts file there and then what you do in your ansible tower and for me i'm just going to be using my same playbooks repository maybe this is not the best practice if you want to kind of separate things out or just name it something different so i'm going to be calling it from the same uh from the same thing repository so anyway go to ansible tower once you have your hosts file created and then you can either create a new project or use the existing project so for example this test project i did before and this was to link up the the playbook in github to ansible tower itself so i'm going to actually just do this on my ddsec one uh because then i can this kind of will help me offline too just to kind of get my stuff together as i start uh once again building out my lab if you want to call it that so this is basically what i'm going to use point is i'm not going to create a project because i already have the project already created and synced up in ansible tower from github itself you see playbooks a playbooks a and you also see because it's private i need a scm credential which is a deep dive sec github pat personal access token so um i'll probably create another video on how to set those things up but for the time being just remember that if it's a private repository then you need to add a credential to access it because otherwise you won't be able to so here if you don't have a project create one or if you have a project already created which you're using for playbooks and you just add your hosts file we'll just use that one next thing you do is go over to inventory and create an inventory here so i'm going to say ddsec github probably don't need github but anyway so what you want to do is you'll notice these are grayed out right here so first thing you need to do is to save your new inventory now these things are opened up so what you do then is you go into sources and you add a new source so i'll just say github because why not so here sourced from a project this is the project in ansible tower that i was we were just looking at a minute ago so we don't need a credential because it's already applied in the project project here ddsec right there okay next thing is update options so here update on launch what this is going to do is any time that this inventory is used so for example the jobs which run the playbooks anytime those jobs run they're going to sync to github first to pull down the most recent update on the playbook so this is really good you just need network connectivity i'd think that it would error out if you cannot access github but then again if your network is down you probably have bigger problems than a ansible playbook so update on launch and then you have other other different ways methods of doing it and you can look at the tool tips and then here this is where it gets a little unclear so inventory file hosts that's the file that i created right well i don't see that in here so probably because you can name hosts anything and then maybe in a config file point to that appropriate thing anyway hosts that's you just type it in there if you'll remember in the setting up the playbook github integration those playbooks were already pre-populated here they're not so there you go hosts and we're going to save okay so now what we can do is we will go down here ddsec github this is the inventory now let's try this start sync when i talk about syncing this is going out to github and trying to pull down that inventory file and then parse it and kind of give you pull out the the appropriate hosts to connect to so what you see here is sync failed okay not the end of the world but something that i observed is that maybe let's just try it one more time but what i did before is i would go into the projects and i would sync from there instead of syncing from here so let's try that and hopefully it'll work so we go to projects remember this is the project that we are connected to for the inventory so let's go here and do that we'll synchronize and then let's go back once this is done we'll go back to the inventory and we'll take a look there okay here so we'll click it and we will go down to sources and let's try it one more time synchronize here so every time that i tried this before worked so this we should see it turning green when it's green it means that your information is kind of you know gotten from github so now we can go to hosts here and these are the items that uh this is your inventory file basically so db web and rel hosts and these are the groups uh rel because all is just default but web db and rel hosts so my inventory i'm going to be using the rel hosts group so just to be aware and just keep in mind too when you run your playbooks you are applying the group in your playbook itself so don't get tripped up to think that you select your group as well in the job you do not you do that in your playbook so here my group is rel hosts and my playbook is rel hosts or whatever you know it would be you just have to match them up okay all right so we are looking good there uh let's let me just uh try to go back there we go all right green good to go now let's go to templates and we'll go to the rel update one and let's change the inventory to ddsec github select and because it's the same playbook name that's all you need to do and once we do that let's save it first and then we'll launch and then we will see if it works remember verbosity if you want to see more of what's going on you probably want to put it more verbose all right so to recap what we did is we used an existing project that had github integration if you don't have one you have to create one but we used a project integrated with github and we connected that to an inventory and after a couple syncs we got the hosts synced up from github right here and then what we're doing here is we are applying that to one of our jobs here and let me launch and i will pause this while it runs and then once it does i think we should be good to go and we're back and the run of this job for the update playbook was successful so you can just see here it's it's using the update.yaml update and reboot and you should see this is the name right there update and reboot and just kind of going through it's just an update it didn't have anything to update so it was pretty quick minute and 43 seconds so well so you can see here inventory ddsec github that's what we did status was successful and uh and that's it uh so another quick recap uh just creating a project here and applying the that project to an inventory updating your template and then running it and that is your integration of your inventory into github so that's all i had for this video and stay tuned for future videos
Info
Channel: CyberScribe.org
Views: 5,514
Rating: undefined out of 5
Keywords:
Id: 9pztTTaNLCA
Channel Id: undefined
Length: 12min 20sec (740 seconds)
Published: Sat May 08 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.