Getting Started with the ios_config Ansible Module

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone this is Jason Edelman and in this video we're going to look at providing an introduction to using the iOS config module in ansible I received a lot of questions over the past several months it's just getting started or danceable how to perform basic operations advancable such as configuring SNMP configuring my nerves ntp and different features like that so in this video we're going to focus on the basics just to show how do you get started what I mean is you're not going to configure complex configurations or complicate yours we're going to start with the bare minimum required in order to show how to configure SNMP contact location and community strings with the ansible iOS config module so we're going to be focused on specifically global configuration commands now on besides that because the way we're going to configure commands another in interface configuration mode router configuration mode and different modes like that will be slightly different so again we're focused more on architecture and more on seeing the different mechanism that can be used within ansible to configure a cisco iOS device now what we're going to do first is do a tree command within Linux we're going to see we have no ansible files yet we simply have a single directory with a single file if you need cat this file we'll see we have five commands this is the desired configuration that we want to have on our Cisco IOS XE device we're going to open this instable on just so we could keep this open and reference this file so this file is now open and we're going to expand our configs on the left just to see all of our configurations that we're going to have which for now is just our SNMP dot CFG fun you have two routers able to us we have csr 1 and csr 2 these are cisco cloud services routers we haven't clear that out we're now going to oh and create a human story file that we're going to use with an answer we're going to close our iOS devices we're going to have CSL one CSR two we're now going to create group variables and ansible again this video isn't going to go into super detail around the underlying antal architecture so that's assume some understanding creating your valuables and inventory files we're going to be focused on just the usage of the iOS config module with an ansible we're going to create some credentials in our group valuables will say NT c SE n T's will say password equals n TC one two three we're going to do control us on this we'll save it and then we'll see it populate and left hand side now what we're going to do is we'll just call a playbook config dot yml and this will be our ansible playbook that we're going to use in order to deploy and configure SNMP on our cisco routers we have two files here and vitória significant iOS and two devices in there so now we're gonna get started our playbook stay on file our three - at the top this is our first play in the playbook so what we're going to say is names or si deploy SNMP commands from file so we're going to show this a few different ways a purse one will be from file actually what we're going to change this we're going to say deploy SNMP configurations we'll do this a different way say configurations what hooks do you want to deploy us on so we'll say both iOS devices and our Google i/os in our image very file so Sipos iOS and we're going to be explicit so it's good just getting started we're going to disable gather facts we're going to say you know otherwise there'd be gathering facts on our local server is in running connection local wood we're running ansible 2.2 so we're going to make sure you're in local load which is how all Jardine networking modules what the display so and we now we need to add our tasks to a playbook our first task will be a deploy a sin MP two figs from file actually not what we're going to do first is deploy SNMP command one of minimize dependencies we're going to play SNMP commands within our playbook this is we're going to introduce the iOS config module well how do we get started here to take module we'll simply browse an salats online or we can use the ansible dock utility this is going to show us all the required parameters that we need and some examples to bottom on how to get started so we can see here there's different mechanisms that we receive so we can look at lines lines as an example you scroll up see what lines or lines or give you the commands that we want another alias for lines commands so I prefer command so we're going to use commands on here this is a parameter called commands which accepts a single command or a list so we're going to say our list of commands that we want to deploy at this point this is going to be our list okay so we're going to copy our commands in here we're going to use a few sublime shortcuts control shift L both the line edit we're going to create our list and then we're going to add our commands into our task and now they are credentials are say username or valuable reference to our inventory file UN password PWD that's the table that we have in our inventory file and there are commands username password and weand our host currently this is going to be inventory who's name though environment references the name of the host as we've defined in the entire file we have csr 1 csr - those are both resolvable names so we can just reference those names and at this point assume control s control us on our playbook this is our desire to sense configuration exit out of here we do an LS we now see we have our config directory still there that our desired commands or config PlayBook config dot yml and arbitrary file so I swore to run this playbook you can say ansel playbook - I inventory and config die animal this is saying run our playbook config dot yeah Mille and a reference arm is right file so here we'll go back to our playbook we see host : iOS host : iOS is in fact referencing the iOS group so we're going to automate limit posts since we don't want to both host just yet we're going to limit this job to just csr 1 to ensure it's going to work properly so when we run our playbook which is going to fail template error file templating strength unexpected strength PWD I also have some real-time troubleshooting here you come back in here we notice I did forget a curly brace I think that was on purpose maybe it Wilson's saying so we're going to come back to control us back to our Linux terminal on our playbook again so we now see our play name our task name and we're now going to see this changed as amber so if we wanted to open a new window up you can simply for now we'll do a new tab I'll say SSH into CSR one will log into this device and to do a show run type include SNMP server you then I'll see our commands on the device and just to show the items to this module meaning the change will not occur again if we won the same playbook this is green okay no change was made okay so as module will only make the change the first time so we can run this over and over again the change will only occur the first iteration but the nice thing is we now prove this out she saw our one is our canary device our test device we can get rid of our limit one this on both devices entire level CSR one CSR to his ansible is natively concurrent so now it says okay csr one the config already gets it on csr one now that says change csr two so now if we log into CSR - that would be good as well if we want to just prove idempotency one more time over on our playbook and now we're going to see green okay for both csr 1 and csr - this is shown one way to get started using the iOS critic module we're going to copy this we're going to paste this down here we have commands again now we want to show another way we're going to say another way we can say just your reference configs SNMP CFG this is going to show us how to deploy directly it's going to config tousle deploy SNMP commands some config file this is where if you want to put your commands in a file go for because reference that file from a single task we also notice you can have multiple tasks to the pledges to username password host username password close little bit redundant so we're going to do now is we're gonna simply define a variable in our plate look at the top ideally this would get moved into a group Barse file just to show a good practice on building a variable and your table to prove it out first so we're going to call this our iOS provider even we'll provide all redundant variables such as username password and flows so we're going to take those out okay at the top we're going to use our typical good practice to stay synthase now we adjust reference that valuable with the provider variable say we're not going to pass in iOS provider as a value of provider parameter now if you are quick look at this we want to see this I am suppose I owe S config you scroll down with the provider providers that convenience method as you see it wasn't required those they can be is that the going forward at 3.2 you will have to start using provider but for now I take convenience mechanism to simplify common arguments between tasks I clear this out so we're now going to do control us we're going to run both tasks and they should be idle poet they're both because all the configuration already exists on the networking devices so this is a little bit redundant but we're showing the different mechanisms we can use the ives config module so we can have our commands and bend it into playbook we can reference a file we can also reference what's called a Jinja to templates now if we look at this we can copy and paste this to deploy it somebody commands directly from a Jinja to template this it can say source we're now going to reference a SNMP j2 file this is a jinja to template answer will automatically looked for templates stored in the tempest directory so we're going to create that and then we're going to say let's open up templates SNMP j2 ok so we're going to expand this we're going to show that down here we're going to migrate to our to pain column layout we're going to have our template over here we're going to reference this template as well so we want to show our configuration this is where we need to be couple inputs our outputs so we're going to also open up another new file we're going to pull route Mars and for now all the Bible's accessible to all devices so we're just going to say this is all diamo we can actually if we want for good practice we're going to remove our provider from our playbook we're going to put that directly in our group waters file we're going fairly quick here just in each time so we're now going to show what this is like we have now have a variable in our all diamo file and requires these variables are available for any device to use consider them defaults if you want it clear and sold on the playbook if you want which is just proving out that the playbook still works after we've migrated it moves the provider into our group waters file so and this is this failed because we don't have our temple yet okay so that was a good failure because our task in our playbook had referenced a template that was not yet each of them so what we need to do is create variables that reference everything we need or config just we're going to copy this temporarily we can see if all on screen so we're going to say we want to create a variable SNMP and there's no right or wrong way to model data if you said this video we're going to pick one way so there's a SNMP and have a dictionary SNMP contact is going to be Jason deke we're going to say our location is the data we want this to be now we want to have this speed ro we'll say ro community strengths say public one two three other one called network to code and then we'll say RW keep it simple we have a nested list how to do lists the dictionaries with typed keys and things like that so we're going to show one way here RW and this is going to be private on two three so now we'll keep that there we're going to do control us now we're going to jujitsu template to consume this data so now one option or the OP so we're going to show is our first contact command so this is going to be our templates and if you serve a community any we need expand this over so the first one will be contact if you serve a contact this is going to be SNMP dot contact so SNMP the first ones referencing our variable name we can do dot key so dot contact location will be the same sold us in a P dot location change this location now we need two for loops to loop over our o + RW again this is one way to model the data simply otherwise typically we would have community strings deal with some dictionaries and change the data have a single old we'll save that as an exercise for the video watcher now we're going to show we could also do for our o community in SNMP dot our oh this is going to be SNMP server community access our valuable ro community and then put our o at the end our for loop and we're going to copy this one and have it one more time for our W communities well typo here we'll come back and grab that one [Music] so we'll do RW RW RW this is a Jinja - template accessing the data in our valuable files to generate these commands okay so now what we could do is believe this we've decoupled our command to data our Yambol variables and a template when we insert our data into our template we're going to have rendered commands so if we're going to adopt good practices to leverage platforms like github to store our novel files you would do a pull request in modify SNMP data right without our template in our playbook and then out comes our commands so this is going to be three ways to do the same exact thing so this is going to be redundant and deploy the same same commands three separate times so we're going to run this our first two times again task 1 we already know this works doing the same exact things we're now deploying directly from a config file we're now sourcing a Jinja - template in the config file and actually saw a change here so what we want to do is really see what's going on here with why this is changing is let's let's try something here where we want to run just this one task so we can tag it I will call this SNMP J - that's our tag so we can adjust one - tags SNMP stop day two and four goes what let's see if this shows us any data this did not make a change because it already made the change we're going to figure out why this had a different attribute on here so state public one two three private never to code public one two three five one two three go to code Jason E and DC HQ and NYC so what we could do if we want to figure this come back to our device we signed out a rehearsal wait for this to come back to us seeing a templates directly so we're going to come back into our device show Ron pipe include SMT server the commands do look the same and TC is chilling C okay so this is why I changed okay so those might have noticed this but one was Jason eat all underscore or lowercase bonus all caps this is why this is why it did change just to prove this out make sure make sure we are good actually let's change our data to jason underscore e we're on our playbook again all three the first one will show a change because we're going to go back to all caps so we're going to say changed here okay we're pulling form a config file deployed commands from agency templates now we're good so we saw this perfect so now we're going to introduce our last way which is going to be generate SNMP config file using the template module so we can source SNMP j2 here the depth we want to store this let's just say this is going to be configs it will say SNMP Auto since we already have a GFG GFG deploy SNMP from auto-generated file at this point you can copy this previous task iOS config to bring your configs SNMP SAS auto these two tasks can be used instead of this one task or this other task yes you have got your option here taking the choosing how to use using the two-step process I consider a common practice since it allows us to build or config files view them first for example we now can say we'll say build tags it's employed okay so what's just run our builds task whereas a ansible playbook - - x equals build so it's only changed once because we're generating the same commands or two devices or end devices so technically speaking this one can be a run once it's all true now if you had unique configurations then you would not not have it run walls so we can now run this again again the builds get already done but only you're only running spawns the Sun so if we do a tree here we're now going to see SNMP Auto this is auto-generated with the template module so if we say cat configs SNM SNMP photo we now see our commands in this file this is auto-generated we verify the commands origin area properly now can just run our deploy task your last task again this is the same configurations we already configured three times so in this short video we showed four different ways that we can simply deploy configurations now option 1 we're great for getting started again we're just focused on global config commands here we're not showing yet how you can do interface commands router bgp commands router o v commands quality of service anything not global configuration mode would be a little bit more complex a little bit more into using the config module we would have to look at other parameters such as parents as an example so feel free to browse ansible Docs or use the ansible - dock utility to understand how to use the I of esthetic module or other config module such as and EXO's config us config you know s config and so on so we're going to look at again is our goals to show how to get started using - static module so we've shown how to embed commands in a playbook we showed how to reference a config file with you just dumping in the commands of the config file we showed how to create a Jinja - template referencing data in our group bars all the yellow file and any valuable in all amyl in route wars is accessible for all devices so our we had two variables iOS provider to simplify credentials and SNMP - as our SNMP data now once you're temple to create your template should never change only your data should change that was another option we then said hey what if we want to verify our commands that are going to take file before we do a deploy if we're going to do this in a proper fashion potentially having different variables different data for different sites because you can have variables for different geographical locations the SNMP settings for asia-pac or EMEA or the US but your template to be the same - oil generate the right commands so you auto-generate it with the template module and then deploy the config module again so this is just showing different ways you can get started using the iOS config module to specifically deploy global configuration demands you have any questions feel free to reach out online through slack you have a slack community that you can self sign up for at slack dot networks to code comm at slack dot network teo koat.com there's various channels available will for reference this video or we can help that ever be online or email us as well you know that info at network to code calm as well and again hope this helps get started with ansible using the iOS to take module
Info
Channel: Jason Edelman
Views: 22,847
Rating: 4.9176955 out of 5
Keywords: ansible, networking, cisco, ios, ntc, networktocode
Id: WXLUgDmvHDI
Channel Id: undefined
Length: 27min 36sec (1656 seconds)
Published: Tue Apr 25 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.