@ -359,14 +359,19 @@ Network CLI filters
To convert the output of a network device CLI command into structured JSON
To convert the output of a network device CLI command into structured JSON
output, use the `` parse_cli `` filter::
output, use the `` parse_cli `` filter::
.. code-block :: yaml
{{ output | parse_cli('path/to/spec') }}
{{ output | parse_cli('path/to/spec') }}
The `` parse_cli `` filter will load the spec file and pass the command output
The `` parse_cli `` filter will load the spec file and pass the command output
through it, returning JSON output. The YAML spec file defines how to parse the CLI output.
through it, returning JSON output. The YAML spec file defines how to parse the CLI output.
The spec file should be valid formatted YAML. It defines how to parse the CLI
The spec file should be valid formatted YAML. It defines how to parse the CLI
output and return JSON data. Below is an example of a valid spec file that
output and return JSON data. Below is an example of a valid spec file that
will parse the output from the `` show vlan `` command.::
will parse the output from the `` show vlan `` command.
.. code-block :: yaml
---
---
vars:
vars:
@ -383,12 +388,15 @@ will parse the output from the ``show vlan`` command.::
state_static:
state_static:
value: present
value: present
The spec file above will return a JSON data structure that is a list of hashes
The spec file above will return a JSON data structure that is a list of hashes
with the parsed VLAN information.
with the parsed VLAN information.
The same command could be parsed into a hash by using the key and values
The same command could be parsed into a hash by using the key and values
directives. Here is an example of how to parse the output into a hash
directives. Here is an example of how to parse the output into a hash
value using the same `` show vlan `` command.::
value using the same `` show vlan `` command.
.. code-block :: yaml
---
---
vars:
vars:
@ -407,9 +415,12 @@ value using the same ``show vlan`` command.::
state_static:
state_static:
value: present
value: present
Another common use case for parsing CLI commands is to break a large command
Another common use case for parsing CLI commands is to break a large command
into blocks that can be parsed. This can be done using the `` start_block `` and
into blocks that can be parsed. This can be done using the `` start_block `` and
`` end_block `` directives to break the command into blocks that can be parsed.::
`` end_block `` directives to break the command into blocks that can be parsed.
.. code-block :: yaml
---
---
vars:
vars:
@ -457,7 +468,9 @@ The spec file should be valid formatted YAML. It defines how to parse the XML
output and return JSON data.
output and return JSON data.
Below is an example of a valid spec file that
Below is an example of a valid spec file that
will parse the output from the `` show vlan | display xml `` command.::
will parse the output from the `` show vlan | display xml `` command.
.. code-block :: yaml
---
---
vars:
vars:
@ -478,12 +491,15 @@ will parse the output from the ``show vlan | display xml`` command.::
desc: description
desc: description
state: ".[@inactive='inactive']"
state: ".[@inactive='inactive']"
The spec file above will return a JSON data structure that is a list of hashes
The spec file above will return a JSON data structure that is a list of hashes
with the parsed VLAN information.
with the parsed VLAN information.
The same command could be parsed into a hash by using the key and values
The same command could be parsed into a hash by using the key and values
directives. Here is an example of how to parse the output into a hash
directives. Here is an example of how to parse the output into a hash
value using the same `` show vlan | display xml `` command.::
value using the same `` show vlan | display xml `` command.
.. code-block :: yaml
---
---
vars:
vars: