Ansible Network Automation | ...with Jinja2!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone its Jon and today what I do is a video on ginger two templates to help you with your network automation so what are ginger two templates well basically it just as a template so what is that and well not to insult anyone's intelligence of course but I thought you know what let's just make this easy to conceptualize and while she's putting up an obvious template I just pulled us over then on earth this is not money in John but and so look at this imagine kaskell think of the user base which they've got say they've maybe they've gone see a good few million emails of people do you really want to be rating that's exactly an email out to every single user and device early know the mind powers would be crazy what you will do effectively here is rate dear and then variable this is going to change this can be anything the rest of it your tape oh okay and all you need to do is just substitute and your email user base that's part here and dear weatherize so be Dear John art whatever and then you get as email and then dear Sarah that's email body blood and a has fallen and thank her effective and efficient not as rather than have any tape out the same no you can probably notice a kind of parallel between it working for generations if you configure in say BGP and you're always taping route of BGP something there's something changes that's the variable that's gonna be that tone my system number that does change but the fact is me are configured in BGP is always a little BGP something and you will always tape a network and then the network might be different but the water layer what's gonna be the same okay so these are the things which I'm going to try a template oh no the reason why that's just so useful is that what if you have a set of horse variables which you don't want to change the route or IP address you I keep the same there are a host name whatever as but let's say you're using it on a different version of Cisco IOS let's say one route or a Cisco IOS the other one is Cisco IOS XR uses slightly from a syntax war F the Deaf ones is even greater and maybe you've got some Cisco rules and some junipers and maybe some rest of us all of a sudden maybe the syntax even though all the host variables are the same you want to keep the same IP addresses but you need to tape them and to the ruler a different way what you're gonna do here is use these templates which is gonna reference what's real it's going to use which template and you can keep the whole video with the same and they will just be paid into that specific template that's effectively what we're going to do in this video so know the way I've set this up I'm cheating a little bit here I'm going to confess what I've got here are 10 rules that all sus carros ok but I'm actually going to do let's pretend the dozen vendors almost because what I'm going to do it is configured EW GFP and all them but the good thing I'm using for ya are PCI grps get two very distinct and very different but compatible ways of taping and if the EIGRP your normal mode your bloody IG RP autonomous system numbers already IG RP 5 and you've also got named modes which is like ro/di GRP John address family ID v for unicast written autonomous system number 5 whatever to pause your base you've got all these different configurations so you get two completely different ways to tape an Mei ji p configurations which would make me the case if you had two that from a rules one make configured OSPF one way one may configure it another now I'm going to show you using gender two templates you can basically just tape out the differences and the configuration once and then just use that as a reference to pay pan your values depending on which workers where F as a general rule I guess I'm the Juniper template efforts are such cool it'll go successful template and the variables all stay the same okay so it keeps things really nice really easy and very very scalable so that's a factor which I'm going to do in this video know what I will say as as always I am NOT a network automation expert far from I'm a beginner and a novice and if you see anything wrong with us please connect me the only reason I'm giving you these videos is a I'm thinking maybe it may be helpful to someone so like I said are free and do with them as you please I'm going to put the actual all the fares up and github after so you can just check the description if you want to use these fails so what that said I'm going to give a little bit of a walnut and that best stuff can be a little bit confusing the first time you see it because and that's radio particularly this would have a lot of cross-referencing with variables and you may find it hard to track this is not an intelligence thing if you just do a knock came you start to follow other the exact same I think everyone who does us is that the same of faucets cannot have to follow where's going where I'm hold it down what we do that how you didn't know you do this trust me it's a replication thing do an octane and you start to see the part so that's a fair walnut okay so now I'm going to start the video and hopefully do my best job I try nice but in this case up as I bet confusing I'm not going to lie but stick what's up and you'll see the value in it okay so let's have a look what we got here so the first time which I want to show you is like I see it as per usual if we did can it see hosts I've basically got my generic DNS can figure the fake to play so when I take penpen are one look at you look up are one and that's horse fail and it's going to resolve it to 191 sexy 55.1 these are all the are effed off sort of get that from em so sure run but I'd margin vrf sore for example that's not a face intercept it vrf so it's not going to be able to be touched by the the production there was gonna be separate from the management network effectively that's what's doing here and these are these IP addresses so we can reach out of band effectively so when I say Pam pang are one that's resolving it to this IP address and it can paying it okay so that's basically what's going on there no heels department is going to get a little bit tricky but stick with it here's the play of it I'm going to start with the playbook first up here so name first player or on me it rules that's just a generic name the horse is gonna be real switch is n or horse fail we're just cat that looks a little but definitely I'll get to this later or using M llamo format rather than ini you can use ini but because we have some inheritance going on I think it's easier yeah move about more casual feel to it you can see which which belong you work just more like a folder structure in Windows you can kind of see it's just easier vegetables I'm using that you can use the ini only use the form a lot but definitely start saying let's the rules a - children whatnot this commercial world inheritances don't worry about that too much you can be done down to a documentation so I can say we're going to use this on the river so cap back on in that cats well play one so I'm going to execute in the rules this is where it gets a little bit tricky okay so we're going to set a fact and we're going to set the fact of an e IG RP path that is what we're going to tell the road dependent on which capable as what template to use and it's going to be in the path of the templates folder and we've got that's variable here E is P oh s tape and then underscore AIG RPG - J 2 as the ginger - Templar so effectively what we're doing is we're using these two special groups which ansible has called kilograms and horse powers the first one what you're referencing as group VARs okay so far the secret VARs and I can't see I GRP named Ritter's okay what's going to happen as for routes which are identified and the horse fail like I say up here as a idea P named rows which are these ones 2 4 6 8 10 they are going to have an OS tape and EIGRP or s tape and their group variable and that is going to be changed from AI gr p OS tape to the water named no that's making series now understand as a lot of kind of bounce around them back and forth and reference and that that's what it's effectively doom sword know for EIG RP name drawers or EIT RP template path becomes templates named underscore CIA RPG 2 so if we go into templates and the cats named dia RPG - that's with a path here because again yeah our POS tape becomes named so it becomes named underscore AIG RPG - which is thus here for those rules that are going to use less template which is that okay clear lots of you but usually see they're gonna use the EIGRP named mode so I'm gonna have a GI GRP variable that's gonna be tough from address found the ipv4 unicast at home system available network variable e IG our period ID variable e IG RP stop variable topology based nor somebody know let's have a look at what those and what does actually are okay so let's have if we go into CD host farce and each one and they go back actually see the host farce what am i I think and so we've got a bunch of all these rows of got that each each have their host variables okay so let's have a look at Row 5 okay so five okay so root of fives got some variables let's just see that a lot so you can see they're all very similar okay so there's that from a definitely odd IDs and whatnot and the Voges same yes and whatnot so effectively what's gonna happen as if we go back and look at em that's template here or e IG RP and these curly braces denote a variable okay and it's basically saying or looking at the dictionary i j RP and dogs actual okay so see there's dot effectively that's how you reference that okay we're going to see i gr p dot virtual which means AI j RP here so i'm talking around that's value here the IP v 0 so effectively walk is putting a template ansible no rates return e IG RP i pv 0 okay f with that yeah grps it's going to look at the EIG RP dot a s means we're going to use this one which means the value is no v so animal will no rate address from the ipv4 unicast autonomous system number of our autonomous system five Magus of system Network yeah ARP don't network okay EW gr p dot network here so the value as 0 0 0 0 0 0 0 0 which is basically advertise all networks and let's continues on e IG RP stop eajy RP don't stop ew gr p dot stop as that's value so effect we're going to tape an e IG RP stop connected and it's based I just like that Tesco email all that stuff as the stuff what it going to have for all these name drugs are always going to have this type 10 they're always going to have less tape 10 that always going to have this tape up that's tape 10 they're always going to have less taped em and just the values are changing effectively ok so let's look at the other m tampons we've got CD templates that was the named one and we've also got the normal one so a cat's normal and it's gonna know what we'll just clear let me make a little bit clearer for you that she's gonna use the the ultimately IG RP which make the more familiar watch the road yeah GRP autonomous system number no wall-e igr PID Network and I'm putting on your knee pen stop time just put on some additional configurations you can see extra stuff obviously don't configure stop network if it's not supposed to be a stop network and and like I say the same without what's this big do cats play when the ruler as a normal eh erp we're gonna go into ansible automatically look integrate VARs as phony CSR a I gr pier or ok which is this one here so we just look at E I gr Peru on the variable substitution here as E is P or s tape which is this part here then becomes the Walt normal so that means the EIGRP path is no and the templates folder and it's no called normal underscore TIG RPG a so they're ansible will then look to templates and look at cat normal on the EIG RP and it's clearly again and it's going to reference that more basic one the more usual one so basically dependent on whereabouts and the horse everything e IG appear or it's going to have CD CD crevasse it's going to have a EIGRP variables variables which are means the waste tape as normal which means that this path becomes normal underscore AIG RP which means the template it's twenty years as the normal why not do an LS stuff which means it uses this template okay like I said with the cat hosts FS an e IG RP named or ie 2 4 6 8 10 that's going to answer looking the group variables for EIG RP named Rose the EIGRP OS tape gets changed to the world named so we go into the playbook ew g our POS tape becomes named underscore da g RP so we're looking at the templates and we do we use this template instead because it's called named so we can't named and we use the definite template okay we use the named modes okay so that's effectively what's happening here well you can see i apologize if s is confusing to understand that but it's as a matter of practice to be honest with you so let's look at the last part of the playbook effectively what you're doing is to get the actual configuration we're gonna use CLI config and the config we're going to use as again as the variable going to look up and let's look up as a feature rounds of what you're going to look up and it can look up certain things it can look up template I can look up URL I can look up fail in this case you want to look up a template okay so ansible and record lookup template and EIGRP path which was the fact which we said which is going to be the path here which again is contingent on which type of ruler we have been being given and the horse fail which will denote which template use which is gonna tell you which can I do what configuration to push out effectively again notify the change register response and but it's gonna basically oppose the response here and that is basically how it's going to work okay so without further ado I think we should go ensure the configuration so like I said none of these routes of get any configurations on them just yet so with the assur run section no ii i GRP nothing now for these are all the same short run section ii i GRP nothing on them so let's go and push out these configurations like i say all the top ones they've been get together they're going to have the normal ear GRP and the bottom one will get up attains a different vendor completely even though it's s cool but when you have completely different sent acts that all going to use E I GFP named mode okay so let's go and one last thing clear up you can tape john-boy answer ball play book play one let's run it so we're going to identify which template use dependent on what host is where and what doing that just now and then the next thing is going to do is actually apply those configurations based on that template and put in those variables so like I say the variables don't have on it to change you can just keep them the same and if you swap out half your production network with no these in your juniper rules just keep the variables the same just change the template and push it all at the juniper you know I mean it's really really simple keeps things very very scalable and it's just much better it's much more manageable effectively so that's that all change we can see that here as denoted let's go into the door so let's have a look at us run a game like I say this one should have M just a normal EA GRP which is the more common way to see there we go really I GRP show IP e IG RP neighbors done labels up but like I say if we go to one of the bottom ones show run section e IG RP s using the deform issues in named mode it's got address family let's get the policy base but it's all the same and s it continued right through the network because like I say above reference and different templates to use sure run section e IG RP s can have a normal one but like I say down here the bottom one that's when you have the name configuration there we go okay so like I say that shows you how the template your configurations and again to look at the horse fails CD host bars they're all pretty much the same a cat one just like differences but I mean what is pushing them out on the different configurations so it doesn't really matter these can all stay the same give us reference in different variables and you get completely different effect depending on which template years so it makes things really really simple and really really manageable okay dope so that's the end of video again I apologize if s is a bit confusing just practice it do it a few teams and I promise you you will absolutely get up so I'm going to put these up on em github like I said and that's the end of video so thanks very much and I'll see you guys soon bye bye
Info
Channel: IPvZero
Views: 3,795
Rating: 4.8596492 out of 5
Keywords: Cisco automation, devnet, cisco, ansible, ansible network, ansible network automation, python cisco, python cisco automation, python network automation, jinja2 network, jinja2 network automation, IPvZero, ipvzero, templates, CCNA, CCNP, Juniper automation, netdevops, network automation programmability, labeveryday
Id: 37CBID_1oOY
Channel Id: undefined
Length: 19min 23sec (1163 seconds)
Published: Sat Oct 26 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.