mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[PR #6043/c168f9c3 backport][stable-6] JC: Add plugin parser functionality to JC Filter Plugin (#6047)
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
(cherry picked from commit c168f9c3be
)
Co-authored-by: Kelly Brazil <kellyjonbrazil@gmail.com>
This commit is contained in:
parent
ff4aff0bef
commit
3802d54922
2 changed files with 10 additions and 2 deletions
2
changelogs/fragments/6043-jc_plugin_parser_support.yml
Normal file
2
changelogs/fragments/6043-jc_plugin_parser_support.yml
Normal 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).
|
|
@ -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')
|
||||
|
||||
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)
|
||||
return jc_parser.parse(data, quiet=quiet, raw=raw)
|
||||
|
||||
|
|
Loading…
Reference in a new issue