Ansible Network Modules | ios_conifg, nxos_config, cli_command

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome to this video on ansible Network modules in today's video I'm going to be looking at some basic and support network modules to perform some configuration tasks and some backup tasks on CSR 1000v routers and a couple Nexus 9kv rooters as well for the simulation of the devices I'm going to be using EVE ng as this platform here if you've not used even G before I would highly recommend you check it out and I will be doing some video tutorials on this in the very near future it's a fantastic way to simulate lab environments so much better in my opinion than gns3 but what we do dig into that a bit later but for now just to show you that I do have three CSR reuters running here and a couple of nexus 9 k V's as well and we're going to be covering the ansible network modules so to find out what they are we need to google ansible Network modules I do that here and when it what modules the first one that comes up will be doc store ansible comm and this is where you can get all the documentation for the network modules now if you're here I presume that you are a network engineer and you're looking to find out more information about this if you've not come across the network modules or even ansible just a quick run-through ansible is a an open source IT automation platform heavily used in the Linux server environment and more recently in the last few years it's been gaining massive popularity in the network community and as you can see here by the amount of network modules that have been created for it you can see it is a heavily used platform now we will be using today the iOS command module and a couple of the nx-os modules as well and so if you want to do anything with ansible configuring your network devices then just jump into the ansible network modules documentation find something that might look like what you want to do and then you can it saves you a huge amount of effort in coding what you're trying to do so for this example we're going to use the iOS command module that is going to run some simple commands and we're also going to be using the iOS config module as well to push some simple config at to those CSR Reuters so let's put this out the way and I'm just going to bring up the devices just to show you that we are dealing with real devices here and I'm not just making this up so we've got a CSR one that's this one here CSR two and CSR 3 so those are the three devices I showed you on running on Eve ng they're running on and ESXi platform in my spare room funnily enough so that's the devices will be coming back to that very shortly but what we're going to do is run this playbook so if this is new to you this is a playbook and this is how you configure ansible to do the configuration tasks that you want it to do first of all you have to define the hosts that you want to automate so in my host file I've got a group called CSR Reuters and in there I've got a CSR one two and three and the IP address of those devices and bit further down these are my Nexus devices that I'm going to connect to it shortly back into the playbook so configure dot yml and if this editor is new to you as well this is Visual Studio code which is my new current favorite editor this is running on my abun to 1804 and this is also my ansible control machine so let's go through the first playbook this is going to push some very simple configuration on to all three rooters and we'll be using for this the iOS underscore config module so the iOS config module and all that's going to do is take the source this network programmer T configs test dot text file so let's just have a look at that so that file is test X and in there very simply I've got user name Steve password test one two three four five so we're gonna push a new user name on to this router very simple but this is just to show you the concept and how this works this could easily be a full route to config based off templates which again we'll go into in much later date but let's take this step step so it's going to target the hosts so this is the house in here this is what it's going to target and it's going to target all the devices in the group CSR Reuters and we're going to push the configuration file this is just a name so this is a description of when the PlayBook runs we're using the iOS config module so that's going to do all the connection and worry about getting to the device and we're just gonna push that very simple config onto all three Reuters so to run that playbook we do ansible - playbook configure it ymo so this is they're going to connect to all three routers and push that one line of configuration onto each one and when it's completed we'll get a change status so we now know that that has completed and we've got hopefully three Reuters configured with the username of Steve as well so if I say show run include username we've now got two usernames on there Roger and Steve CSR to show Ron clued username Steve and Steve so we've got three usernames on the devices now that's a very simple process now what we're going to do now is remove the usernames off those devices so I'm going to use this code here didn't drop on neatly so for this one we're gonna use a different and scible Network module where you can use iOS user and what this one's gonna do is just say for the user named Steve going to be state absent which means remove it now I'm using the iOS user module one just to show you a different module in use and secondly the main reason is on the CSR Reuters when you remove a user name and it actually prompts you to confirm that you want to do that and ansible stick at that point if you just push the config no user name so we're going to use a different module just to show how this works so all this is gonna do is push the file so we're gonna reconfigure the name Steve and it's gonna remove it and take it off so we already know the user named Steve is on there so let's just run the player but once more so it is gonna run through it again and then at the end it's going to rip it off okay so this is now removing the username of Steve and that tells me it's completed so now if I go back into these devices and show username you can see Steve has been taken off one two and three now I'm going to add one more little bit in here just to show you that did work and I'm gonna use a feature called paws so if you've got a lot of play books and big play books and you want to just check things along the way before it times a or fails you can just put paws in here now if you just leave paws on its own I'll wait for a prompt if you could if you want you can put a timeout on it so now we don't have the user named Steve on those three devices so we're gonna run the playbook again it's going to configure the username Steve put it back on and then it's going to wait without pause command and there we go and there's the pause so now the playbooks waiting for me to come on and hit enter to say carry on you can use this for many things you can wait for a bgp neighbor to come up you can wait for validation but we're just gonna use it just to show you this so I'm going to show running clewd username and steve has gone back on again on three on two and on one and then hit enter play but we'll continue and it's gonna remove it off once more what do you show run username and you can see it's gone so that's the iOS user module and also the iOS config module I'm just gonna remove that Paul's it's gonna get in the way so and I will show you another console or network module which I only discovered this a few days ago actually which is the iOS ping module which will ping and that's gone a bit too far now this is Yama and Yama is very picky about indentation so it has to be exactly right this will ping a IP address from the device which is very handy so what we're gonna do now is just show you actually bring over the documentation again and so we're gonna use the iOS ping test reach ability using ping from a Cisco Network device know the answer documentation is very good so this will tell you a new in version 2.4 test for each ability using ping from switch to a remote destination and these are all the options that you've got with it and here are some example configurations so you can just use it from the default vrf if you've got different VRS and you want to test from within them you just verify BRF and the name of the vrf in there you can also define a source interface as well so that's the configuration options and I've just got it to ping my default Rooter on the home lab here so let's go back in we run the whole playbook again what its gonna do is configure Steve and then rip it off once more and then it's gonna ping Chrome each device the the IP address of the router and this should come back green if you've if we've got a success with this iOS ping module so Steve's gone on Steve's come off again and I can get reach ability to this IP address and then just to prove this I let's just change the IP address so this is now 1.2 so this will fail because that IP address is not live on the network and we're just gonna configure uncommon fig those usernames again this time we should get three failures on the ping that does say there 1.1 that is just a name that's the description of the task which I didn't change on the configuration show you there so that's just a description that's the name of the task so I did so I should have just put a dot too but that's not gonna affect the operation this is the actual address that it's going to ping then we'll go back and we can see we've now failed on those three and which is a nice little test so if you're pushing out some routing changes once you've pushed the change I you could put a ping in you could put a pause in just to test a few things before you progressed on with the other changes so there's three little iOS modules we're gonna go and show you a couple more so it's something that I use and support for I would probably say the most most use case for it is to do backups so if I'm staging equipment anywhere working I just take some backups of the devices for those of you that are new to the channel forgot to introduce myself my name is Roger Parkin I am CCIE fifty thousand and thirty eight I work for a Cisco NGO partner here in the UK and I'm getting heavily into network automation and programmability so I'm using ansible to help me with the day job basically to try and save me time on tasks so this one here is my favorite playbook this is a backup playbook the code here just creates a directory for me and the directory is named with today's date I'm not going to go into too much detail on that now but just understand that this is gonna just create me a folder to put these backups in and then we're going to target the Reuters and the CSR Reuters group and then we're going to target the Nexus devices so there's two Nexus 9k bees and for this one we are using the iOS command module and the command I'm gonna push to those three CFS are Reuters is show run it then registers the output from that as a variable called config and then it saves that into this folder but it also saves it with the device name I've got all this formatting on here which will save the Rueter name and today's date in the correct folder there the nx-os does the same thing but we're using a different answer bull network module and we're using the nx-os config module but with the backup yes option so this is actually designed for doing Nexus configuration so if you wanted to configure the Nexus devices you would use this module and then at the end of the play but run you would put backup yes but I'm just using it just to do the backup so we got an X OS config module backup yes and then it's got an option to provide the file name of the backup file so this basically says the name of my device and the date and in the right folder which we'll see in a moment and this is the path where to save those backups so let's run that one and see what that looks like screen ansible playbook backup top white mo now that playbook has been run many times today so the folder has already been created the folder is called 2019 - 10 - 10 so that's today's date it's running show run on the three CSR Reuters and then it's put the output of that into the backups folder now orange means it's changed so the configuration has changed on those devices and it's also changed on the Nexus devices so let's run it once more doing this live what should happen is everything should stay green because no changes have been made to the config since the last time I made a configuration on the devices now that is a feature with an answer wall called idempotency and it means that if you try to push a change that doesn't need to be pushed or do something that doesn't need to be done or is already in that state ansible won't do it so we've got Nexus backed up and we got CSRs backed up and to go through here I will just show you where they've put those backup files so I've got a folder yeah the folders called backups this is today's date 2019 10:10 and I've got five backup files so it's the device name the date and then - config so there's the CSRs backup file here is the other one and then the Nexus backups here so this is my Nexus 9 k1 and this is Nexus 9 k2 so there you have it so that's a brief run-through of the ansible network modules that i've used I use most we've done some configuration and some backups if you want to learn more about this I do have an answer ball Network automation course the description for that and will be below there's a link to that you can find out more about that and as I said my name is Roger Perkin and if you really enjoy this then please hit that thumbs up and subscribe then when I make new videos you will get notified of them thanks for your time and I look forward to seeing you in the next video
Info
Channel: Roger Perkin
Views: 8,245
Rating: 5 out of 5
Keywords: roger perkin, roger perkin ansible, ansible network modules, ansible tutorial, ansible network automation example, ansible network cisco, ansible network automation cisco, ansible network automation modules, ansible, ansible playbook, ansible cisco, ansible cisco automation, ansible for network engineers, cisco, netdevops, network programmability, network automation, ansible modules, ansible cisco ios_command example, ansible cisco examples
Id: zMkqhC6KT3c
Channel Id: undefined
Length: 20min 25sec (1225 seconds)
Published: Thu Oct 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.