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

JC: Add plugin parser functionality to JC Filter Plugin #6043

Merged
merged 6 commits into from
Feb 23, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions plugins/filter/jc.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,14 @@ def jc_filter(data, parser, quiet=True, raw=False):
raise AnsibleError('You need to install "jc" as a Python library on the Ansible controller prior to running jc filter')

try:
jc_parser = importlib.import_module('jc.parsers.' + parser)
return jc_parser.parse(data, quiet=quiet, raw=raw)
# new API (jc v1.18.0 and higher) allows use of plugin parsers
if hasattr(jc, 'parse'):
return jc.parse(parser, data, quiet=quiet, raw=raw)

# old API (jc v1.17.7 and lower)
else:
jc_parser = importlib.import_module('jc.parsers.' + parser)
return jc_parser.parse(data, quiet=quiet, raw=raw)

except Exception as e:
raise AnsibleFilterError('Error in jc filter plugin: %s' % e)
Expand Down