On 04. feb. 2017 20:27, czopereq76 wrote:
> 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.
>
> ---
> - 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: VLAN NUMBER
set_fact:
vlan_index: {{ sh_vlan_output.stdout[0].vlans.keys() | map('int') |
list | max + 1 }}
This should do what you are looking for.
--
Kai Stian Olstad