community.general.jc filter – Convert output of many shell commands and file-types to JSON
Note
This filter plugin is part of the community.general collection (version 6.6.2).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install community.general
.
You need further requirements to be able to use this filter plugin,
see Requirements for details.
To use it in a playbook, specify: community.general.jc
.
New in community.general 1.1.0
Synopsis
Convert output of many shell commands and file-types to JSON.
Uses the jc library.
Requirements
The below requirements are needed on the local controller node that executes this filter.
jc installed as a Python library (https://pypi.org/project/jc/)
Input
This describes the input of the filter, the value before | community.general.jc
.
Parameter |
Comments |
---|---|
The data to convert. |
Positional parameters
This describes positional parameters of the filter. These are the values positional1
, positional2
and so on in the following example: input | community.general.jc(positional1, positional2, ...)
.
Parameter |
Comments |
---|---|
The correct parser for the input data. For example Note: use underscores instead of dashes (if any) in the parser module name. See https://github.com/kellyjonbrazil/jc#parsers for the latest list of parsers. |
Keyword parameters
This describes keyword parameters of the filter. These are the values key1=value1
, key2=value2
and so on in the following example: input | community.general.jc(key1=value1, key2=value2, ...)
.
Parameter |
Comments |
---|---|
Set to Choices:
|
|
Set to Choices:
|
Examples
- name: Install the prereqs of the jc filter (jc Python package) on the Ansible controller
delegate_to: localhost
ansible.builtin.pip:
name: jc
state: present
- name: Run command
ansible.builtin.command: uname -a
register: result
- name: Convert command's result to JSON
ansible.builtin.debug:
msg: "{{ result.stdout | community.general.jc('uname') }}"
# Possible output:
#
# "msg": {
# "hardware_platform": "x86_64",
# "kernel_name": "Linux",
# "kernel_release": "4.15.0-112-generic",
# "kernel_version": "#113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020",
# "machine": "x86_64",
# "node_name": "kbrazil-ubuntu",
# "operating_system": "GNU/Linux",
# "processor": "x86_64"
# }
Return Value
Key |
Description |
---|---|
The processed output. Returned: success |
Collection links
Issue Tracker Repository (Sources) Submit a bug report Request a feature Communication