Hi All,
I am trying to add VLAN according to the last number available on the
switch. In my case right now the last VLAN number is 100 so I would like to
add next one with number 101. However running my playbook it looks like
iteration over VLAN list is not in order and playbook created VLAN 15
instead of 101.
I would like to run iteration in order from 1 to 100 and then create VLAN
101. Does any one know how to achieve this?
---
- name: CHECK VLAN
hosts: eos
connection: local
tasks:
- name: CHECK FOR VLAN NUMBERS
eos_command:
commands: show vlan | json
provider: "{{ cli }}"
ignore_errors: yes
register: sh_vlan_output
- debug: var=sh_vlan_output.stdout[0].vlans.keys()
- name: SET VLAN NUMBER
set_fact:
vlan_index: "{{ item | int +1 }}"
with_items:
- "{{ sh_vlan_output.stdout[0].vlans.keys() | sort }}"
- debug: var=vlan_index
- name: CREATE VLAN
eos_config:
lines:
- vlan {{ vlan_index }}
provider: "{{ cli }}"
authorize: yes
PLAY [CHECK VLAN]
**************************************************************
TASK [setup]
*******************************************************************
ok: [eos-1]
TASK [CHECK FOR VLAN NUMBERS]
**************************************************
ok: [eos-1]
TASK [debug]
*******************************************************************
ok: [eos-1] => {
"sh_vlan_output.stdout[0].vlans.keys()": [
"11",
"10",
"13",
"12",
"14",
"1",
"100"
]
}
TASK [SET VLAN NUMBER]
*********************************************************
ok: [eos-1] => (item=10)
ok: [eos-1] => (item=1)
ok: [eos-1] => (item=100)
ok: [eos-1] => (item=11)
ok: [eos-1] => (item=12)
ok: [eos-1] => (item=13)
ok: [eos-1] => (item=14)
TASK [debug]
*******************************************************************
ok: [eos-1] => {
"vlan_index": "15"
}
TASK [CREATE VLAN]
*************************************************************
changed: [eos-1]
PLAY RECAP
*********************************************************************
eos-1 : ok=6 changed=1 unreachable=0 failed=0
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/7cb6fecb-8f36-4fec-a828-5932e53c0b82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.