Skip to content

vlan_parser

Collection Note

This module is part of the ansible.netcommon collection. To install the collection, use:

ansible-galaxy collection install ansible.netcommon
Added in version 1.0.0.

Synopsis

  • The filter plugin converts a list of vlans to IOS like vlan configuration.
  • Converts list to a list of range of numbers into multiple lists.
  • C(vlans_data | ansible.netcommon.vlan_parser(first_line_len = 20, other_line_len=20))

Parameters

Parameter Defaults / Choices Comments
data
list
required
This option represents a list containing vlans.
first_line_len
int
Default: 48
The first line of the list can be first_line_len characters long.
other_line_len
int
Default: 44
The subsequent list lines can be other_line_len characters.

Notes

Note

  • The filter plugin extends vlans when data provided in range or comma separated.

Examples

# Using vlan_parser

- name: Setting host facts for vlan_parser filter plugin
  ansible.builtin.set_fact:
    vlans:
      [
        100,
        1688,
        3002,
        3003,
        3004,
        3005,
        3102,
        3103,
        3104,
        3105,
        3802,
        3900,
        3998,
        3999,
      ]

- name: Invoke vlan_parser filter plugin
  ansible.builtin.set_fact:
    vlans_ranges: "{{ vlans | ansible.netcommon.vlan_parser(first_line_len = 20, other_line_len=20) }}"


# Task Output
# -----------
#
# TASK [Setting host facts for vlan_parser filter plugin]
# ok: [host] => changed=false
#   ansible_facts:
#     vlans:
#     - 100
#     - 1688
#     - 3002
#     - 3003
#     - 3004
#     - 3005
#     - 3102
#     - 3103
#     - 3104
#     - 3105
#     - 3802
#     - 3900
#     - 3998
#     - 3999

# TASK [Invoke vlan_parser filter plugin]
# ok: [host] => changed=false
#   ansible_facts:
#     msg:
#     - 100,1688,3002-3005
#     - 3102-3105,3802,3900
#     - 3998,3999

Authors

  • Steve Dodd (@idahood)