• Zach Biles

Useful Ansible Ad-Hoc Commands

Ansible doesn’t always have to be crazy complex playbooks doing super cool stuff. Sometimes, it’s really useful to get some output from al your devices like versioning, VLANs, IP addresses, etc... Here I plan to collect some of the one-liners I end up using so others can see what’s possible. This will be a dynamic post, so check back over time!


Find if a VLAN exists on your gear:

This command string will run a ”show vlan brief” command on your devices, and return the output. Then only include lines based on the grep filter. Basically, if the line in the output contains Changed, error, failed, or unreachable it will include this in the output. This way, you can see which device might not have been online or failed to return output. Then it will also include lines with the VLAN number you are looking for. In this case, 4092.

ansible all -i switch_hosts -m raw -a "show vlan brief" | grep 'CHANGED\|ERROR\|FAILED\|UNREACHABLE\|4092'

Check for a specific line in your configuration file:

This command will look run “show running-config” on your devices and return back if “service password encryption” is in your configuration. This is something you should always have enabled on Cisco devices.

ansible all -i switch_hosts -m raw -a "show running-config | include service" | grep 'CHANGED\|ERROR\|FAILED\|UNREACHABLE\|encryption'

6 views0 comments

Recent Posts

See All

MikroTik RouterOS v7

Just a collection of changes/quirks I'm noticing so far in RouterOS v7 beta releases. I plan to keep this updated as I continue to play more with v7. When importing public keys you can now use passwor