Using 'jc' parser in 'ansible.utils.cli_parse' module

I’d like to use the ‘jc’ parser in the module ‘ansible.utils.cli_parse’ but I cannot figure out to set the jc specific parser in the module parameter. When I try the following …

    - ansible.utils.cli_parse:
        command: ps
        parser:
          name: community.general.jc
          vars:
            parser: ps
        set_fact: _ps_output

… I get the error fatal: [localhost]: FAILED! => {"changed": false, "msg": "Error loading parser: No module named 'ansible_collections.community.general.plugins.sub_plugins'"}

I believe that ‘jc’ is functioning otherwise as that below provides a nice JSON list of dicts.

    - ansible.builtin.command: ps
      register: _ps_output

    - ansible.builtin.debug:
        msg: "{{ _ps_output.stdout | community.general.jc('ps') }}"

community.general.jc is a filter plugin, not a sub-plugin for the ansible.utils.cli_parse module. So you cannot use it with ansible.utils.cli_parse, unfortunately.

1 Like

Thanks for the clarification. The cli_parse docs are not exactly clear what sub-plugins are supported, though on a re-read, there is no reference to jc. However in the more general docs on cli parsing under the section on the cli_parse module, jc is specifically mentioned as being supported with the that module, is this a different thing, or an error in the docs?

Hmm, that was added in Add JC filter plugin example by kellyjonbrazil · Pull Request #74563 · ansible/ansible · GitHub, but I think that PR was wrong and it should never have been added to that section.

I’ve created a PR to remove it from that section: Remove incorrect parts from docs by felixfontein · Pull Request #2388 · ansible/ansible-documentation · GitHub

1 Like