[cisco.meraki.meraki_switchport] Problem with the clean the "vlan"
y0rune opened this issue · 7 comments
Hello!
I would like to clean the vlan on the specific port. I created the .yml
file for it:
---
- name: Configure SW_E0_10
hosts: localhost
connection: local
gather_facts: false
collections:
- cisco.meraki
- cisco.meraki.meraki_ms_stack
- cisco.meraki.meraki_organization
vars_files:
- ../vars/vars.yml
tasks:
- name: Get port SW_E0_10_2/49
cisco.meraki.meraki_switchport:
auth_key: "{{ MERAKI_API_KEY }}"
serial: "{{ SERIAL_SW_E0_10_2 }}"
name: "UP LINK"
state: query
number: 49
- name: Configure port SW_E0_10_2/49
cisco.meraki.meraki_switchport:
auth_key: "{{ MERAKI_API_KEY }}"
serial: "{{ SERIAL_SW_E0_10_2 }}"
name: "UP LINK"
state: present
number: 49
type: trunk
allowed_vlans: "all"
vlan: null
poe_enabled: no
After run it I got:
yorune@Gentoo-d9yc132 ~/git/wtt-infrastructure-meraki main $ ansible-playbook -e "MERAKI_API_KEY=$MERAKI_API_KEY" playbooks/SW_E0_10_TEST.yml -vv
PLAYBOOK: SW_E0_10_TEST.yml ************************************************************************************************************************************1 plays in playbooks/SW_E0_10_TEST.yml
PLAY [Configure SW_E0_10] **************************************************************************************************************************************META: ran handlers
TASK [Get port SW_E0_10_2/49] **********************************************************************************************************************************task path: /home/yorune/repo/wtt-infrastructure-meraki/playbooks/SW_E0_10_TEST.yml:13
ok: [localhost] => {"changed": false, "data": {"access_policy_type": "Open", "allowed_vlans": "all", "enabled": true, "isolation_enabled": false, "link_negotiation": "Auto negotiate", "link_negotiation_capabilities": ["Auto negotiate", "1 Gigabit full duplex (auto)", "1 Gigabit full duplex (forced)"], "name": "UP LINK", "poe_enabled": false, "port_id": "49", "port_schedule_id": null, "rstp_enabled": true, "stp_guard": "disabled", "tags": [], "type": "trunk", "udld": "Alert only", "vlan": 1, "voice_vlan": null}, "response": "OK (unknown bytes)", "status": 200}
TASK [Configure port SW_E0_10_2/49] ****************************************************************************************************************************task path: /home/yorune/repo/wtt-infrastructure-meraki/playbooks/SW_E0_10_TEST.yml:21
ok: [localhost] => {"changed": false, "data": {"access_policy_type": "Open", "allowed_vlans": "all", "enabled": true, "isolation_enabled": false, "link_negotiation": "Auto negotiate", "link_negotiation_capabilities": ["Auto negotiate", "1 Gigabit full duplex (auto)", "1 Gigabit full duplex (forced)"], "name": "UP LINK", "poe_enabled": false, "port_id": "49", "port_schedule_id": null, "rstp_enabled": true, "stp_guard": "disabled", "tags": [], "type": "trunk", "udld": "Alert only", "vlan": 1, "voice_vlan": null}, "response": "OK (unknown bytes)", "status": 200}
META: ran handlers
META: ran handlers
PLAY RECAP *****************************************************************************************************************************************************localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
In the api site I found out the information about:
I tried curl connection:
yorune@Gentoo-d9yc132 ~/git/wtt-infrastructure-meraki main $ curl --silent --request PUT -H 'Content-Type: application/json' -H 'X-Cisco-Meraki-API-Key: '$MERAKI_API_KEY'' -d '{"vlan": "null"}' https://api.meraki.com/api/v1/devices/$SERIAL_SW_E0_10_2/switch/ports/49
{"errors":["'vlan' must be an integer or null"]}%
So I would like to ask how I can clean the vlan field?
Thank you!
I see the problem. You want to remove the VLAN from the port? Definitely an interesting problem with how Ansible handles types. I may add an absent
option which when specified removes the VLAN. Thank you for reporting this.
Yeah yeah!
In the our configuration we do not use the vlan and from the web we can do it. So i think that think it should be enabled via API or Ansible.
Thank you for response.
I did some experimentation and looks like your curl
request isn't correct. I'm not sure how to pass null
via curl
but you're passing a string. I'm investigating how to do this on my end. My current approach is if vlan: 0
is provided it clears the VLAN.
If I run the curl:
yorune@Gentoo-d9yc132 ~ master $ curl --silent --request PUT -H 'Content-Type: application/json' -H 'X-Cisco-Meraki-API-Key: '$MERAKI_API_KEY'' -d '{"vlan": 0}' https://api.meraki.com/api/v1/devices/$SERIAL_SW_E0_10_2/switch/ports/49
{"errors":["Native VLAN must be a number between 1 and 4094"]}%
So I think the api only accept the values between 1 and 4094
If I run the curl:
yorune@Gentoo-d9yc132 ~ master $ curl --silent --request PUT -H 'Content-Type: application/json' -H 'X-Cisco-Meraki-API-Key: '$MERAKI_API_KEY'' -d '{"vlan": 0}' https://api.meraki.com/api/v1/devices/$SERIAL_SW_E0_10_2/switch/ports/49 {"errors":["Native VLAN must be a number between 1 and 4094"]}%
So I think the api only accept the values between 1 and 4094
Agreed but I have the luxury of interpreting and manipulating the data as part of the module since it's Python.
I just submitted a PR to fix this. Please test using this change.
Okey!
I changed in the playbook from None
to 0
(as docs suggest) and changed the requirements to your repo and branch it worked!
Run the changed playbook:
---
- name: Configure SW_E0_10
hosts: localhost
connection: local
gather_facts: false
collections:
- cisco.meraki
- cisco.meraki.meraki_ms_stack
- cisco.meraki.meraki_organization
vars_files:
- ../vars/vars.yml
tasks:
- name: Get port SW_E0_10_2/49
cisco.meraki.meraki_switchport:
auth_key: "{{ MERAKI_API_KEY }}"
serial: "{{ SERIAL_SW_E0_10_2 }}"
name: "UP LINK"
state: query
number: 49
- name: Configure port SW_E0_10_2/49
cisco.meraki.meraki_switchport:
auth_key: "{{ MERAKI_API_KEY }}"
serial: "{{ SERIAL_SW_E0_10_2 }}"
name: "UP LINK"
state: present
number: 49
type: trunk
allowed_vlans: "all"
vlan: 0
poe_enabled: no
TASK [Get port SW_E0_10_2/49] **********************************************************************************************************************************task path: /home/yorune/repo/wtt-infrastructure-meraki/playbooks/SW_E0_10_TEST.yml:13
ok: [localhost] => {"changed": false, "data": {"access_policy_type": "Open", "allowed_vlans": "all", "enabled": true, "isolation_enabled": false, "link_negotiation": "Auto negotiate", "link_negotiation_capabilities": ["Auto negotiate", "1 Gigabit full duplex (auto)", "1 Gigabit full duplex (forced)"], "name": "UP LINK", "poe_enabled": false, "port_id": "49", "port_schedule_id": null, "rstp_enabled": true, "stp_guard": "disabled", "tags": [], "type": "trunk", "udld": "Alert only", "vlan": 1, "voice_vlan": null}, "response": "OK (unknown bytes)", "status": 200}
TASK [Configure port SW_E0_10_2/49] ****************************************************************************************************************************task path: /home/yorune/repo/wtt-infrastructure-meraki/playbooks/SW_E0_10_TEST.yml:21
changed: [localhost] => {"changed": true, "data": {"access_policy_type": "Open", "allowed_vlans": "all", "enabled": true, "isolation_enabled": false, "link_negotiation": "Auto negotiate", "link_negotiation_capabilities": ["Auto negotiate", "1 Gigabit full duplex (auto)", "1 Gigabit full duplex (forced)"], "name": "UP LINK", "poe_enabled": false, "port_id": "49", "port_schedule_id": null, "rstp_enabled": true, "stp_guard": "disabled", "tags": [], "type": "trunk", "udld": "Alert only", "vlan": null, "voice_vlan": null}, "response": "OK (unknown bytes)", "status": 200}
Run it again:
TASK [Get port SW_E0_10_2/49] **********************************************************************************************************************************task path: /home/yorune/repo/wtt-infrastructure-meraki/playbooks/SW_E0_10_TEST.yml:13
ok: [localhost] => {"changed": false, "data": {"access_policy_type": "Open", "allowed_vlans": "all", "enabled": true, "isolation_enabled": false, "link_negotiation": "Auto negotiate", "link_negotiation_capabilities": ["Auto negotiate", "1 Gigabit full duplex (auto)", "1 Gigabit full duplex (forced)"], "name": "UP LINK", "poe_enabled": false, "port_id": "49", "port_schedule_id": null, "rstp_enabled": true, "stp_guard": "disabled", "tags": [], "type": "trunk", "udld": "Alert only", "vlan": 1, "voice_vlan": null}, "response": "OK (unknown bytes)", "status": 200}
TASK [Configure port SW_E0_10_2/49] ****************************************************************************************************************************task path: /home/yorune/repo/wtt-infrastructure-meraki/playbooks/SW_E0_10_TEST.yml:21
changed: [localhost] => {"changed": true, "data": {"access_policy_type": "Open", "allowed_vlans": "all", "enabled": true, "isolation_enabled": false, "link_negotiation": "Auto negotiate", "link_negotiation_capabilities": ["Auto negotiate", "1 Gigabit full duplex (auto)", "1 Gigabit full duplex (forced)"], "name": "UP LINK", "poe_enabled": false, "port_id": "49", "port_schedule_id": null, "rstp_enabled": true, "stp_guard": "disabled", "tags": [], "type": "trunk", "udld": "Alert only", "vlan": null, "voice_vlan": null}, "response": "OK (unknown bytes)", "status": 200}
It worked! I think you can merge it :D
Thank you!