ansible-network / network-engine

This role provides the foundation for building network roles by providing modules and plugins that are common to all Ansible Network roles.
GNU General Public License v3.0
112 stars 53 forks source link

How to handle minor variations (is it possible to do "if")? #237

Open joubbi opened 5 years ago

joubbi commented 5 years ago

I am creating templates for some Cisco IOS devices. Unfortunately Cisco is not consistent with the output on some of their commands across IOS versions and devices.

For example the command "show vtp status" outputs:

VTP version running             : 2

on some switches. And this on others:

VTP Version                     : 2

Is it possible to handle this with an if statement or or? (regexp like this, if null then regexp like this instead). Or something similar to this:

pattern_match:
    regex: "VTP Version capable             : (.*)" | "VTP Version                     : (.*)"

Also the amounts of whitespace between names and variables differ on different devices:

Number of existing VLANs          : 34
Number of existing VLANs        : 8

I haven't found any examples or documentation on how to handle these situations.

EDIT: I solved this particular problem with this regex:

regex: "VTP \\Sersion [r|\\s][u|\\s][n|\\s][n|\\s][i|\\s][n|\\s][g|\\s]             : (.*)"

Still I would like to know if there is a possibility to do an if statement. Also more documentation would be very helpful.