Wednesday, April 17, 2019

Python concepts into Ansible

I’m hopthing someone who has been in a similar situation can help me here. A little background....I’m relatively new to Ansible - I can write basic playbooks to see Cisco iOS output, pull out some data from ios_facts, etc. Prior to attempting to automate with Ansible I learned and got comfortable with python. I love python in the fact I can do anything I need to with it.

Now, we need to scale automation across 10,000+ devices so I need a tool/platform that can accommodate and thus the reason for exploring Ansible. Here is what I’m attempting to do and want to know if this is even possible with Ansible and how would I go about accomplishing:

  • if/then statements in Ansible....how can you program these. I’ve heard of conditionals and using when: but not sure if that would work in all cases (see specific example below I’ve been trying to solve)
  • have a playbook execute a python script (which I can currently get to happen) but then pull in output from that script back into the playbook for addition plays or tasks. Is this even possible? If so, how?
  • parse an output from any iOS command and take action based upon the output. For example, one specific use-case I have is to look at multiple switches, show interfaces | include interface|CRC >> if any switch has CRC’s, clear interface counters in that switch, wait 10 minutes and run the command again. If CRCs still increase, do something (send email, etc)

Or, am I trying to fit a square peg into a round hole? That is certainly what it feels like but I’m hoping it’s just that I’m new to Ansible. I really want to leverage the programming concepts from python with the scalability of Ansible and create some great automation in my network. Thanks for any help!



No comments:

Post a Comment