From 91212b2008f3f75e855fd9e74194c05e7a6acd50 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 14 May 2021 08:37:29 -0700 Subject: [PATCH] Add JC filter plugin example (#74563) Co-authored-by: Abhijeet Kasurde --- .../rst/network/user_guide/cli_parsing.rst | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/docsite/rst/network/user_guide/cli_parsing.rst b/docs/docsite/rst/network/user_guide/cli_parsing.rst index aa50892b7de..605759fd0b5 100644 --- a/docs/docsite/rst/network/user_guide/cli_parsing.rst +++ b/docs/docsite/rst/network/user_guide/cli_parsing.rst @@ -56,6 +56,8 @@ The ``cli_parse`` module includes the following cli_parsing plugins: A library for semi-structured text parsing using templates, with added capabilities to simplify the process ``pyats`` Uses the parsers included with the Cisco Test Automation & Validation Solution +``jc`` + A python module that converts the output of dozens of popular Linux/UNIX/macOS/Windows commands and file types to python dictionaries or lists of dictionaries. Note: this filter plugin can be found in the ``community.general`` collection. ``json`` Converts JSON output at the CLI to an Ansible native data structure @@ -583,6 +585,29 @@ The task sets the follow fact as the ``interfaces`` fact for the host: state: up +Parsing with JC +----------------- + +JC is a python library that converts the output of dozens of common Linux/UNIX/macOS/Windows command-line tools and file types to python dictionaries or lists of dictionaries for easier parsing. JC is available as a filter plugin in the ``community.general`` collection. + +The following is an example using JC to parse the output of the ``dig`` command: + +.. code-block:: yaml + + - name: "Run dig command and parse with jc" + hosts: ubuntu + tasks: + - shell: dig example.com + register: result + - set_fact: + myvar: "{{ result.stdout | community.general.jc('dig') }}" + - debug: + msg: "The IP is: {{ myvar[0].answer[0].data }}" + +- The JC project and documentation can be found `here `_. +- See this `blog entry `_ for more information. + + Converting XML -----------------