{"id":13604562,"url":"https://github.com/jasonbarbee/ansible-cisco-inventory","last_synced_at":"2025-04-12T02:30:56.432Z","repository":{"id":217531888,"uuid":"80555131","full_name":"jasonbarbee/ansible-cisco-inventory","owner":"jasonbarbee","description":"Ansible Tooling for Cisco Inventory, Smartnet, and Diagrams","archived":false,"fork":false,"pushed_at":"2017-06-02T19:49:37.000Z","size":4282,"stargazers_count":60,"open_issues_count":0,"forks_count":14,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-11-07T09:43:03.987Z","etag":null,"topics":["ansible","cisco","cisco-inventory","inventory","smartnet"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jasonbarbee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-01-31T19:42:01.000Z","updated_at":"2024-10-23T02:23:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"7fd4f2d1-00bf-4ad5-ac23-5d45bf57ac68","html_url":"https://github.com/jasonbarbee/ansible-cisco-inventory","commit_stats":null,"previous_names":["jasonbarbee/ansible-cisco-inventory"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonbarbee%2Fansible-cisco-inventory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonbarbee%2Fansible-cisco-inventory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonbarbee%2Fansible-cisco-inventory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jasonbarbee%2Fansible-cisco-inventory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jasonbarbee","download_url":"https://codeload.github.com/jasonbarbee/ansible-cisco-inventory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248506901,"owners_count":21115503,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","cisco","cisco-inventory","inventory","smartnet"],"created_at":"2024-08-01T19:00:47.960Z","updated_at":"2025-04-12T02:30:54.833Z","avatar_url":"https://github.com/jasonbarbee.png","language":"Python","funding_links":[],"categories":["ansible"],"sub_categories":[],"readme":"# Ansible Cisco Inventory\n\n## Cisco Assessment Toolkit\n### Features:\n* Inventory\n    * Routers\n    * Switches\n    * UCS FI,Chassis,Compute resources.\n    * Callmanager Devices (coming soon)\n* SNMP Discovery and Graphing\n* Mass configuration changes\n* Export to Cisco My Devices + Cisco Smartnet Totalcare\n* Ansible with NTC-Ansible preloaded.\n\n## Why use this?\n1. No SNMP or discovery, no collector required.\n2. Future Automation - Ansible is a powerful automation tool.\n3. Inventory isolation - No data leaves the network other than the CSV.\n4. Cisco My Devices - EOX reports and contract renewal quoting for customers.\n5. Cisco My Devices - IOS version reports. Soon suggested versions, PSIRTs, and defer notices.\n6. Export data to Cisco Totalcare using this toolset.\n7. Assessment tooling to run mass commands and backups for auditing your network.\n\n## Manual Install is at the bottom of the page.\n\n## Docker - the easy way\nI built a Docker image that has everything pre-built and ready to run all tooling.\nIt will export all files on /mnt, to your mounted folder you pass to Docker.\n*Do not save anything inside Docker!*\n\nCopy your inventory to /mnt like below, and edit it on your local machine outside of docker.\n\n```\ndocker pull jasonbarbee/ansible-cisco-inventory\ndocker run --net=host -it -v $(pwd):/mnt jasonbarbee/ansible-cisco-inventory:latest\ncp /ansible/inventory.yml /mnt/inventory.yml\nansible-playbook -i /mnt/inventory.yml ios-inventory.yml\n\n```\nQuick explanation of what's going on there- \n-v mounts a local folder as a volume\n$(pwd) returns the local path you are in to mount it to the /mnt folder inside docker.\nthe -it calls for an interactive session (bash shell)\nCAUTION: If you are new to Docker.... Docker containers do not SAVE any data except in the shared volume area.\n\nLet's say you have a folder on your desktop for inventories. You can mount that and use the Docker Ansbile to reference that, and just run the host file inventory tool inside the container.\n\nDocker will write a mydevices.csv file inside the container. This will not persist past your session, you must copy this out. \nI plan to address this in the near future with a environment variable...TODO.\n\nFor now, take the mydevices.csv output and copy it to the mount folder.\n\n```\ncp mydevices.csv /mnt\n```\n\n# Discover and Diagram a network\nThe Docker image is preloaded with MNet. This will scan the network via a root node, scan each CDP neighbor and build a decent diagram of the network.\n\nLook in the /mnet folder\nEdit the mnet.conf with your SNMP Strings and exclusion information. \nVI is included in the docker image for easy editing. \n\nUsage:\n```\ncd /mnet\n./mnet.py graph -t MyCustomer -f /mnt/mycustomer.svg -r 192.168.1.1 -c mnet.conf\n```\nMake sure to use the /mnt path so the diagram will export to your mounted folder outside docker.\n\nDiagram Example\n![Diagram](screenshots/diagram.png)\n\n# Discover a network to build an Ansible File of the devices found.\nRun MNET Above but add a parameter to write discovered data to CSV.\n```\ncd /mnet\n./mnet.py graph -t MyCustomer -f /mnt/mycustomer.svg -r 192.168.1.1 -c mnet.conf -C /mnt/mnet-discovered.csv\n```\nNow - convert that to Ansible format\n```\n./mnet2ansible.py -i /mnt/mnet-discovered.csv -o /mnt/discovered-inventory.yml\n```\n\nYou will get a file like this\n```yaml\n[discovered]\n10.10.10.10\n10.10.10.11\n10.10.10.11\n```\n\n# Now to Configure Ansible\nI am using Ansible as a CLI parsing tool. So as long as we can login via SSH, we are good. Even telnet in some cases.\nMost modules **require SSH**. \nYou can use Ansible and Telnet to provision SSH if you are lacking.\n\nAn example - config playbook (config-ssh.yml) is included if you need some guidance on bulk enabling ssh through telnet.\n\nGetting Started:\n1. ansible.cfg should be ntc-ansible folder. It forces the library folder local for NTC-Ansible to load in the same folder. It's automatically loaded in the Docker image, and on this repo.\n2. Onboard devices with Ansible inventory file\nMode Basic Example\n```yaml\n[routers]\n192.168.1.1\n\n[all:vars]\nusername='username'\npassword='password'\nport=22\nclient='MyClientName'\nconnection='ssh'\nport=22\n```\nA more common example is pre-loaded in the repo to allow you to group things together.\nLike calling \"routers\" to include all your telnetrouters and ssh routers like this.\nJust fill in the IPs and use the framework provided.\n\n```yaml\n[sshrouters]\n192.168.1.1\n\n[sshrouters:vars]\nport=22\nconnection='ssh'\nplatform='cisco_ios_ssh'\n\n[telnetrouters]\n192.168.1.2 \n\n[telnetrouters:vars]\nconnection='telnet'\nplatform='cisco_ios'\nport=23\n\n[routers:children]\nsshrouters\ntelnetrouters\n\n[routers:vars]\nusername='username'\npassword='password'\n```\n\n# UCS Inventory\nTo export a UCS inventory, which also works with Cisco My Devices - \nEdit your inventory.yml file with something like this, example in the repo here.\n```yaml\n[ucs]\n192.168.1.3\n\n[ucs:vars]\nucs_username='admin'\nucs_password='secret'\n```\n\n```bash\n$ ansible-playbook -i /mnt/inventory.yml ucs-inventory.yml\n```\nYou will get a file - */mnt/ucs.csv*. This file can be uploaded straight to Cisco My Devices Tool (below)\nIf using Docker - copy this file off to /mnt (shared folder path)\n\n# Router/Switch Inventory\nScan the network\n```bash\n$ ansible-playbook -i /mnt/inventory.yml ios-mydevices.yml\n```\nYou will get a file - */mnt/mydevices.csv*. This file can be uploaded straight to Cisco My Devices Tool (below)\nIf using Docker - copy the configs OFF the Image to /mnt (shared folder path)\n\n## Uploading to Cisco MyDevices\n## [Cisco MyDevices Tool](https://cway.cisco.com/mydevices/)\n\n* Choose Add New Devices and Import using the CSV Template option.\n( Don't worry about duplicates, or all the module serial numbers. It will be helpful in the reports.) \n\n# You can capture more data if you want.\n### Customizing Options Tags and Notes fields:\n1. open up the cisco-mydevices.yml file\n2. collect the data you want (this may include using other playbooks)\n3. Include the variable in the has string and again in the CSV parsing output.\n\nI am capturing 2 \"TAGS\" - Version, and IP Address in the default code.\n\n* Now you can run EOX reports on any Device or module in the entire scan!\n* You can also share your Device Information with up to 15 other people for smartnet quoting or rough inventory review.\n\n## See all your Inventory, modules, Site Address, and Contract info.\n![](screenshots/MyDevices-cleaned.png)\n\n## Cisco MyDevice View Per Chassis\n![](screenshots/Device-View-Cleaned.png)\n\n## See EOX Reports for your Cisco Network\n![](screenshots/EOL-Report-Cleaned.png)\n\n## See your Contracts at a glance.\n![](screenshots/Contract-Renewal-Cleaned.png)\n\n# Onboarding to Totalcare\nSelect all the devices and click Download in SNTC 3.x Format.\n![](screenshots/Totalcare-export.png)\n\nNow you can import this file to Totalcare. Setting up Totalcare is beyond the scope here.\n\n# Backup the entire network configs too.\n```bash\n$ ansible-playbook -i inventory.yml backup-configs.yml\n```\nIf using Docker - copy the configs OFF the Image to /mnt\n\n# FAQ\n### SSH won't connect to very old Cisco devices, dhe key is too small\nhttps://www.petenetlive.com/KB/Article/0001245\n\n### Backups Fail for Old Devices?\nPyNTC and NTC-Ansible seem to be adding the global_delay_factor in as a parameter. As of 3/1/2017, that is a pending pull-request and not committed yet.\nI'm not interested in forking to support an alternate branch in this transition.\n\nQuick fix:\n\nsudo (your-editor) /usr/local/lib/python2.7/dist-packages/pyntc/devices/ios_device.py\nChange your block of code for the backup function to this. It just doubles the timer, and works great.\nTested on 2950s, 3560s, 2800s, 3850s, 2960Xs...\n```python2\n    def backup_running_config(self, filename):\n        with open(filename, 'w') as f:\n            f.write(self.native.send_command_timing('show running-config'))\n            self.native.send_command_timing('\\n',delay_factor=2)\n            self.native.find_prompt()\n        return True\n```\n\n### How about Telnet?\nYes - via NTC-Ansible. Many of their modules support telnet, including the ntc_config_command, ntc_show_command. However, ntc_save_config does not support telnet. \n\npass in parameters to NTC-Ansible like this\n```\nconnection: 'telnet'\nport: 23\n```\nAn example is included in the report as config-ssh.yml\n\n## Manual Install \n\n## To install on Ubuntu - you need Ansible and NTC-Ansible\n1. Install Ansible\nhttp://docs.ansible.com/ansible/intro_installation.html\n\n2. Install NTC-Ansible into the working folder with this playbook.\nhttps://github.com/networktocode/ntc-ansible\n\n    * Option 1 usually works best.\nOne simple way to fix Ansible paths for this to work is to create a new folder for this repo, then clone this repo into it.\n```git clone https://github.com/networktocode/ntc-ansible --recursive```\n\nExample that should work every time\n```\n$ git clone https://github.com/networktocode/ntc-ansible.git --recursive\n$ wget https://github.com/jasonbarbee/ansible-cisco-inventory/archive/master.zip ansible-inventory.zip\n$ unzip master.zip\n$ cp ansible-cisco-inventory/* ntc-ansible\n$ cd ntc-ansible\n```\n\nTest your NTC Code library paths. If it does not work, my script will not work. \nIf you get a working Help Document from this command you are good to go.\n```\n$ ansible-doc ntc_file_copy\n```\n\n### Install NTC-Ansible Depedencies\n```\npip install ntc-ansible\nsudo apt-get install zlib1g-dev libxml2-dev libxslt-dev python-dev\npip install terminal\n```\n\n## Project Roadmap in Order of Priority\n* Export from SNMP discovery to Ansible hosts file.\n* Exporting Host data for Cisco CLI Analyzer Tool direct input\n* Alternate username/password attempt. \n* Try to make Telnet more comprehensive.\n* Network inventory database for persistent storage\n\n## Contributing\nI'm open to any pull requests, contact me or submit a pull request and let's make this better.\n\n## Helpful Resources to Learn Ansible Tricks\n[Ansible Tricks](http://perfspy.blogspot.com/2016/06/ansible-tricks.html)\n[Ansible Language Examples](https://github.com/ansible/ansible-examples)\n## License\nMIT License\nJason Barbee\n\n## Credits\nMany thanks for the following projects used heavily in this toolkit.\n\n* MNet Suite is GPL licensed by Michael Laforest.\nhttps://github.com/MJL85/mnet\n* NTC-Ansible is Apache Licensed by Jason Edelman.\n* Ansible is GPL v3 licensed. Original creator - Michael DeHaan.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonbarbee%2Fansible-cisco-inventory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjasonbarbee%2Fansible-cisco-inventory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjasonbarbee%2Fansible-cisco-inventory/lists"}