Enable \ Disable Network port with Ansible

I was asked by one of my SE’s if Ansible could enable or disable a network port on a switch. My initial thought was, I don’t know, but knowing Ansible, yes it can.

Enough of that, lets get into it.

The module I ended up using was the IOS_intefaces module. The previous module was called IOS_interface but is deprecated. Upon finding the new module I wrote out this quick little playbook. This will disable port 1/0/1 on the switch. Nothing fancy , but it works.

There are some pre-req linux installs that need to be on the system. Paramiko needs to loaded but in order for it to be loaded you also need the following

dnf install -y python-devel
dnf install -y libffi-devel
dnf install -y openssl-devel

Once you have those loaded run the following

pip3 install paramiko

Once you load that things should work, but here is my playbook.

hosts: "{{ host }}" 
false connection: local 
 name: Add MOTD Banner
     - name: GigabitEthernet1/0/1
       enabled: False 

There is much more you can do with this command, and to enable just change the False to True.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s