Using Ansible for Meraki

xaviervalette
Here to help

Using Ansible for Meraki

Hello Meraki community 🙂,

 

This year, I wrote an article about Ansible and Meraki on Cisco Blog, to illustrate how a concrete usecase could be addressed with Ansible,

 

https://gblogs.cisco.com/fr/reseaux/jai-teste-ansible-pour-meraki/,

 

Here is the translation in English for those who are interested :

 

I tested... Ansible for Meraki!

 

Meraki, Cisco's cloud-native solution, has its own Ansible collection,

 

For a solution that can be managed in GUI mode via the Meraki Dashboard ("at scale"), you might well wonder what the point of this collection is.

 

Let's take a concrete example!

 

Let's take the example of a network administrator who needs to update the trunk ports of his network, to add freshly created VLANs:

 

task-1-1536x400.jpg

 

"Easy! "With Meraki's Virtual Stacking (not to be confused with StackWise Virtual under IOS-XE), all we have to do is select all the ports we want to update, edit them, and add the new VLANs to the list of authorized VLANs:

 

meraki_updatetrunk-4-2048x684.jpg

 

It's as simple as that, if the whole LAN is in Meraki:

 

env_simple-3-2048x714.jpg

But even if our network administrator has chosen Meraki as the standard (convinced of the solution's simplicity and scalability), making his network homogeneous is not always easy (recovery of existing hardware, company takeovers, decentralized technological decisions, etc.).

 

His environment will look more like this:

 

 

env_complexe-2-2048x710.jpg

 

Same task, but a much more complex deployment...

 

It's out of the question for our network administrator to go round each vendor's management console, or worse still, to update the configuration of each piece of equipment one by one, using CLI/GUI. The operation would be too laborious, risky and costly. This is where the Ansible collection comes into its own.

 

Let's install Ansible for Meraki

 

ansiblemerakicatalyst-1-2048x556.jpg

 

We need to install Ansible, but not only that. In a network context, Ansible often uses SSH to interact with devices (as is the case in this article). However, Ansible can also use other means of transport, such as REST APIs. This is how Ansible will drive the Meraki dashboard.

 

installation-2-768x478.jpg

 

So let's install the elements needed to use Meraki's REST APIs via Ansible:

 

 

# Installing Ansible
xvalette@lab cisco-meraki-ansible % python3 -m pip install --user ansible
# Install Meraki SDK
xvalette@lab cisco-meraki-ansible % python3 -m pip install --user meraki
# Command for Mac OS users
xvalette@lab cisco-meraki-ansible % export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

 

 

Let's create a playbook

 

hierarchy-768x304.jpg


We want to update the VLANs allowed on the trunk ports,

Inspecting the collection documentation, we find the devices_switch_ports module to meet our needs,

From the documentation and examples, we arrive at the following playbook:

 

 

- hosts: localhost
   vars:
      network_id: L_00000000000000 | to be replaced
      serial_number: XXXX-XXXX-XXXX | to be replaced
      meraki_api_key: clé API | to be replaced
   gather_facts: false
   tasks:
   - name: Update Allowed VLANs on trunk ports
      cisco.meraki.devices_switch_ports:
         meraki_api_key: "{{meraki_api_key}}"
         state: present
         serial: "{{serial_number}}"
         portId: 4
         allowedVlans: 42-44,100-200

 

 

All set!


We can launch our playbook. No need for inventory, since Ansible will drive the Meraki dashboard, not the equipment.

 

 

xvalette@lab cisco-meraki-ansible % ansible-playbook playbooks/updateAllowedVlanTrunk.yml

 

 

oldvsnew-1536x847.jpg

 

In conclusion


In previous articles, we have used :

 

Today we've just seen how to use Ansible with Meraki,

 

In this way, managing a heterogeneous network becomes less laborious, less risky and less costly for our network administrator:

 

env_solved-2048x981.jpg

 

References

 

Xavier VALETTE
1 Reply 1
RaphaelL
Kind of a big deal
Kind of a big deal

Great article ! 

 

Bon travail Xavier !

Get notified when there are additional replies to this discussion.