1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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

* Add plugin parser functionality to JC Filter Plugin

The parse function was added in jc v1.18.0 which allows plugin parsers to be used. This change will try the new API if available, else fallback to the old API so there is no change in behavior.

* remove whitespace from blank line

* Add changelog fragment for JC plugin parser support

* add .yml extension to file name

* Formatting

* add period at end
This commit is contained in:
Kelly Brazil 2023-02-23 07:54:38 -08:00 committed by GitHub
parent a7e8e95b50
commit c168f9c3be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- jc filter plugin - added the ability to use parser plugins (https://github.com/ansible-collections/community.general/pull/6043).

View file

@ -138,6 +138,12 @@ 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') raise AnsibleError('You need to install "jc" as a Python library on the Ansible controller prior to running jc filter')
try: try:
# 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) jc_parser = importlib.import_module('jc.parsers.' + parser)
return jc_parser.parse(data, quiet=quiet, raw=raw) return jc_parser.parse(data, quiet=quiet, raw=raw)