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 task-1-1536x400.jpg](https://community.meraki.com/t5/image/serverpage/image-id/38306i8C5B7C859EFD9D50/image-dimensions/523x136?v=v2)
"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 meraki_updatetrunk-4-2048x684.jpg](https://community.meraki.com/t5/image/serverpage/image-id/38307i18F0B2E1B4BD4469/image-dimensions/652x218?v=v2)
It's as simple as that, if the whole LAN is in Meraki:
![env_simple-3-2048x714.jpg env_simple-3-2048x714.jpg](https://community.meraki.com/t5/image/serverpage/image-id/38308iA255400A285254F0/image-size/large?v=v2&px=999)
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 env_complexe-2-2048x710.jpg](https://community.meraki.com/t5/image/serverpage/image-id/38309i77343AB8EEF7AE10/image-size/large?v=v2&px=999)
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 ansiblemerakicatalyst-1-2048x556.jpg](https://community.meraki.com/t5/image/serverpage/image-id/38311iCC50000493BB816F/image-size/large?v=v2&px=999)
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 installation-2-768x478.jpg](https://community.meraki.com/t5/image/serverpage/image-id/38310i9D142090F34F4221/image-dimensions/319x199?v=v2)
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 hierarchy-768x304.jpg](https://community.meraki.com/t5/image/serverpage/image-id/38312i2341BCB46FECD98E/image-dimensions/389x154?v=v2)
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 oldvsnew-1536x847.jpg](https://community.meraki.com/t5/image/serverpage/image-id/38313iA9E210170972C55D/image-size/large?v=v2&px=999)
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 env_solved-2048x981.jpg](https://community.meraki.com/t5/image/serverpage/image-id/38314i372688921181CB34/image-size/large?v=v2&px=999)
References
Xavier VALETTE