Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add docs for vlan_parser filter #57498

Merged
merged 1 commit into from Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 41 additions & 9 deletions docs/docsite/rst/user_guide/playbooks_filters.rst
Expand Up @@ -602,7 +602,7 @@ address. For example, to get the IP address itself from a CIDR, you can use::
{{ '192.0.2.1/24' | ipaddr('address') }}

More information about ``ipaddr`` filter and complete usage guide can be found
in :doc:`playbooks_filters_ipaddr`.
in :ref:`playbooks_filters_ipaddr`.

.. _network_filters:

Expand Down Expand Up @@ -804,6 +804,38 @@ is an XPath expression used to get the attributes of the ``vlan`` tag in output

.. note:: For more information on supported XPath expressions, see `<https://docs.python.org/2/library/xml.etree.elementtree.html#xpath-support>`_.

Network VLAN filters
````````````````````

.. versionadded:: 2.8

Use the ``vlan_parser`` filter to manipulate an unsorted list of VLAN integers into a
sorted string list of integers according to IOS-like VLAN list rules. This list has the following properties:

* Vlans are listed in ascending order.
* Three or more consecutive VLANs are listed with a dash.
* The first line of the list can be first_line_len characters long.
* Subsequent list lines can be other_line_len characters.

To sort a VLAN list::

{{ [3003, 3004, 3005, 100, 1688, 3002, 3999] | vlan_parser }}

This example renders the folllowing sorted list::

['100,1688,3002-3005,3999']


Another example Jinja template::

{% set parsed_vlans = vlans | vlan_parser %}
switchport trunk allowed vlan {{ parsed_vlans[0] }}
{% for i in range (1, parsed_vlans | count) %}
switchport trunk allowed vlan add {{ parsed_vlans[i] }}

This allows for dynamic generation of VLAN lists on a Cisco IOS tagged interface. You can store an exhaustive raw list of the exact VLANs required for an interface and then compare that to the parsed IOS output that would actually be generated for the configuration.


.. _hash_filters:

Hashing filters
Expand Down Expand Up @@ -1332,8 +1364,8 @@ type of a variable::
Computer Theory Assertions
```````````````````````````

The ``human_readable`` and ``human_to_bytes`` functions let you test your
playbooks to make sure you are using the right size format in your tasks - that
The ``human_readable`` and ``human_to_bytes`` functions let you test your
playbooks to make sure you are using the right size format in your tasks - that
you're providing Byte format to computers and human-readable format to people.

Human Readable
Expand Down Expand Up @@ -1396,17 +1428,17 @@ to be added to core so everyone can make use of them.

.. seealso::

:doc:`playbooks`
:ref:`about_playbooks`
An introduction to playbooks
:doc:`playbooks_conditionals`
:ref:`playbooks_conditionals`
Conditional statements in playbooks
:doc:`playbooks_variables`
:ref:`playbooks_variables`
All about variables
:doc:`playbooks_loops`
:ref:`playbooks_loops`
Looping in playbooks
:doc:`playbooks_reuse_roles`
:ref:`playbooks_reuse_roles`
Playbook organization by roles
:doc:`playbooks_best_practices`
:ref:`playbooks_best_practices`
Best practices in playbooks
`User Mailing List <https://groups.google.com/group/ansible-devel>`_
Have a question? Stop by the google group!
Expand Down
2 changes: 2 additions & 0 deletions docs/docsite/rst/user_guide/playbooks_filters_ipaddr.rst
@@ -1,5 +1,7 @@
:orphan:

.. _playbooks_filters_ipaddr:

ipaddr filter
`````````````

Expand Down