As I was preparing the materials for Ansible 2.7 Update webinar sessions I wanted to dive deeper into declarative configuration modules, starting with “I wonder what’s going on behind the scenes”
No problem: configure EEM applet command logging on Cisco IOS and execute an ios_interface module (more about that in another blog post)
Next step: let’s see how multi-platform modules work. Ansible has net_interface module that’s supposed to be used to configure interfaces on many different platforms significantly simplifying Ansible playbooks.
I hate Ansible’s “let’s develop almost-identical but differently-named modules for every platform” approach to network automation and use NAPALM wherever possible.
Starting with the ios_interface sample playbook, I changed ios_interface call into net_interface, ran the playbook on IOS and NX-OS devices, and failed miserably:
What could possibly go wrong? Here’s a slide from my Ansible for Networking Engineers webinar explaining how platform-independent modules really work:
Got it? The net_interface module is just a thin layer of veneer using platform-specific something_interface modules (selected based on ansible_network_os variable) to do the real work.
Still doesn’t explain the failure, does it? Let’s check the parameters of ios_interface and nxos_interface (the modules implementing net_interface behind the scenes):
ios_interface (and eos_interface) has a single parameter (state) specifying interface state. It can take four values: present, absent, up and down. nxos_interface has two parameters: state which accepts values present and absent, and admin_state which can be up or down.
You can probably see the problem by now: there’s absolutely no way you could bring an IOS and a NX-OS interface in UP state using the same set of parameters.
Old woodworkers had a saying that might be applicable to many software projects not just Ansible: “measure twice, cut once.” In this particular case it seems we’re in the “I cut it three times and it’s still too short” territory 🙁