<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Python or ansible script to shutdown interfaces that are unused AND in a specific VLAN in Controllers</title>
    <link>https://community.cisco.com/t5/controllers/python-or-ansible-script-to-shutdown-interfaces-that-are-unused/m-p/4395171#M2236</link>
    <description>&lt;P&gt;With ansible, I was able to put together a playbook that shutdown any port in the "down" state or "notconnect" state. The only issue was, I could't also filter it by a certain vlan (meaning I didn't know how to). Is there a way with netmiko to shutdown a port in the notconnet or down state, and also in a specific vlan?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a link to my playbook I currently use for ansible......&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Alston518/Ansible-IOS-/blob/main/Shutdown%20Unused%20Port%20IOS" target="_blank" rel="noopener"&gt;https://github.com/Alston518/Ansible-IOS-/blob/main/Shutdown%20Unused%20Port%20IOS&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works to see the port states and issue a shutdown commdand anything not being used (not connect state or down state). It looks at the state and basically if it isnt "up", it issues a shutdown command.&lt;/P&gt;&lt;P&gt;What can I add to that to make it only issue it to unused ports in a specific vlan? When I run the iosfacts, I get a ton of interface info, but nothing about what vlan it is on.&lt;/P&gt;</description>
    <pubDate>Thu, 29 Apr 2021 02:01:43 GMT</pubDate>
    <dc:creator>Alston518</dc:creator>
    <dc:date>2021-04-29T02:01:43Z</dc:date>
    <item>
      <title>Python or ansible script to shutdown interfaces that are unused AND in a specific VLAN</title>
      <link>https://community.cisco.com/t5/controllers/python-or-ansible-script-to-shutdown-interfaces-that-are-unused/m-p/4395171#M2236</link>
      <description>&lt;P&gt;With ansible, I was able to put together a playbook that shutdown any port in the "down" state or "notconnect" state. The only issue was, I could't also filter it by a certain vlan (meaning I didn't know how to). Is there a way with netmiko to shutdown a port in the notconnet or down state, and also in a specific vlan?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a link to my playbook I currently use for ansible......&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/Alston518/Ansible-IOS-/blob/main/Shutdown%20Unused%20Port%20IOS" target="_blank" rel="noopener"&gt;https://github.com/Alston518/Ansible-IOS-/blob/main/Shutdown%20Unused%20Port%20IOS&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works to see the port states and issue a shutdown commdand anything not being used (not connect state or down state). It looks at the state and basically if it isnt "up", it issues a shutdown command.&lt;/P&gt;&lt;P&gt;What can I add to that to make it only issue it to unused ports in a specific vlan? When I run the iosfacts, I get a ton of interface info, but nothing about what vlan it is on.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 02:01:43 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-or-ansible-script-to-shutdown-interfaces-that-are-unused/m-p/4395171#M2236</guid>
      <dc:creator>Alston518</dc:creator>
      <dc:date>2021-04-29T02:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: Python or ansible script to shutdown interfaces that are unused AND in a specific VLAN</title>
      <link>https://community.cisco.com/t5/controllers/python-or-ansible-script-to-shutdown-interfaces-that-are-unused/m-p/4395250#M2237</link>
      <description>&lt;P&gt;You would need to pull the configuration back from the device and parse the details for the interfaces which are on the VLAN. Based on a simple if statement you could shut the ports based on their status, VLAN etc..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a look at pyATS example here&amp;nbsp;&lt;A href="https://pubhub.devnetcloud.com/media/pyats/docs/aetest/examples.html" target="_blank"&gt;https://pubhub.devnetcloud.com/media/pyats/docs/aetest/examples.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 07:12:52 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-or-ansible-script-to-shutdown-interfaces-that-are-unused/m-p/4395250#M2237</guid>
      <dc:creator>bigevilbeard</dc:creator>
      <dc:date>2021-04-29T07:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: Python or ansible script to shutdown interfaces that are unused AND in a specific VLAN</title>
      <link>https://community.cisco.com/t5/controllers/python-or-ansible-script-to-shutdown-interfaces-that-are-unused/m-p/4395478#M2238</link>
      <description>&lt;P&gt;Thanks I will check that out. I am new to automation so trying to understand it all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Will CiscoConfParse or TextFSM accomplish this too? I have never used either of those but was looking on reddit and someone suggested those. From my understanding, I can use TextFSM to find the interfaces I am looking for. Will it just put it in a normal text file, similar to a host file for ansible or netmiko?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like if I want to use textfsm and netmiko to accomplish this, what will the host file look like? Is it a list of IPs and interfaces?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 13:37:15 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-or-ansible-script-to-shutdown-interfaces-that-are-unused/m-p/4395478#M2238</guid>
      <dc:creator>Alston518</dc:creator>
      <dc:date>2021-04-29T13:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: Python or ansible script to shutdown interfaces that are unused AND in a specific VLAN</title>
      <link>https://community.cisco.com/t5/controllers/python-or-ansible-script-to-shutdown-interfaces-that-are-unused/m-p/4395626#M2239</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/501453"&gt;@Alston518&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have found is that is it not just one tool but which tool is best for what you are trying to do or for your environment. &amp;nbsp; You can certainly do what you want with Netmiko. &amp;nbsp;In truth, when I start having to do more complicated logic I generally move away from Ansible and go a python based module (nornir, pyATS, etc.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The repo below can give you some ideas on what you can do with Netmiko. &amp;nbsp; It has a simple script that takes in a layer 3 device and will build you a list of CDP neighbors. This is your "inventory" file. &amp;nbsp;You can then take that list and feed it to another script that gets and parses show commands. &amp;nbsp;Basically what you were already thinking..a list of IPs or FQDNs. &amp;nbsp;I like to save these things in JSON files (or YAML) so they are easy to read but also easy to pass the information into a subsequent script. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/cldeluna/client_discovery" target="_blank" rel="noopener"&gt;https://github.com/cldeluna/client_discovery&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;This might also give you some ideas:&lt;/P&gt;&lt;P&gt;&lt;A href="https://gratuitous-arp.net/configuration-creation-with-nornir/" target="_blank" rel="noopener"&gt;https://gratuitous-arp.net/configuration-creation-with-nornir/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think pyATS would work very well for you too. &amp;nbsp;Makes the parsing a bit easier. &amp;nbsp; I wind up working alot with Netmiko because I often have to run scripts from a restricted Windows system where I can't install things like WSL for pyATS but I can install portable Python. &amp;nbsp;If you don't have those kinds of restrictions, do check out pyATS.&lt;/P&gt;&lt;P&gt;&lt;A href="https://gratuitous-arp.net/getting-started-with-pyats-and-genie/" target="_blank" rel="noopener"&gt;https://gratuitous-arp.net/getting-started-with-pyats-and-genie/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are many "right" ways to solve your problem and I'm glad you are looking at the whole field!&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 18:08:15 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-or-ansible-script-to-shutdown-interfaces-that-are-unused/m-p/4395626#M2239</guid>
      <dc:creator>Claudia de Luna</dc:creator>
      <dc:date>2021-04-29T18:08:15Z</dc:date>
    </item>
  </channel>
</rss>

