ansible / ansible-runner

A tool and python library that helps when interfacing with Ansible directly or as part of another system whether that be through a container image interface, as a standalone tool, or as a Python module that can be imported. The goal is to provide a stable and consistent interface abstraction to Ansible.
Other
968 stars 356 forks source link

Got KeyError when using ansible.posix.json as callback plugin #1261

Closed NitroCao closed 1 year ago

NitroCao commented 1 year ago

How to reproduce:

The output is:

ansible-playbook [core 2.15.0] config file = /etc/ansible/ansible.cfg configured module search path = ['/home/nitro/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3.11/site-packages/ansible ansible collection location = /home/nitro/.ansible/collections:/usr/share/ansible/collections executable location = /usr/bin/ansible-playbook python version = 3.11.3 (main, Apr 5 2023, 15:52:25) [GCC 12.2.1 20230201] (/usr/bin/python) jinja version = 3.1.2 libyaml = True Using /etc/ansible/ansible.cfg as config file host_list declined parsing /home/nitro/Development/vulnk8s/ansible/hosts as it did not pass its verify_file() method script declined parsing /home/nitro/Development/vulnk8s/ansible/hosts as it did not pass its verify_file() method auto declined parsing /home/nitro/Development/vulnk8s/ansible/hosts as it did not pass its verify_file() method Parsed /home/nitro/Development/vulnk8s/ansible/hosts inventory source with ini plugin [WARNING]: Found both group and host with same name: master ERROR! Unexpected Exception, this is probably a bug: 'json_indent' the full traceback was:

Traceback (most recent call last): File "/usr/lib/python3.11/site-packages/ansible/cli/init.py", line 659, in cli_executor exit_code = cli.run() ^^^^^^^^^ File "/usr/lib/python3.11/site-packages/ansible/cli/playbook.py", line 156, in run results = pbex.run() ^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/ansible/executor/playbook_executor.py", line 119, in run self._tqm.load_callbacks() File "/usr/lib/python3.11/site-packages/ansible/executor/task_queue_manager.py", line 203, in load_callbacks self._stdout_callback = callback_loader.get(self._stdout_callback) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/ansible/plugins/loader.py", line 855, in get return self.get_with_context(name, *args, *kwargs).object ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/ansible/plugins/loader.py", line 906, in get_with_context obj.init(instance, args, **kwargs) # pylint: disable=unnecessary-dunder-call ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/nitro/.local/lib/python3.11/site-packages/ansible_runner/display_callback/callback/awx_display.py", line 343, in init super(CallbackModule, self).init() File "/usr/lib/python3.11/site-packages/ansible_collections/ansible/posix/plugins/callback/json.py", line 76, in init self._json_indent = self.get_option('json_indent') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/ansible/plugins/callback/init.py", line 173, in get_option return self._plugin_options[k]


KeyError: 'json_indent'
```

Linux distro: Arch Linux.
Ansible version: 2.15.0
Python version: 3.11.3
ansible-runner version: 2.3.3, installed via pip command.
NitroCao commented 1 year ago

By the way, it works fine when executing ansible-playbook directly. My workaround is to catch the exception and initialize self._json_indent to 0 in the exception handler.

Igorgro commented 1 year ago

Yes, having exactly the same issue when calling ansible-runner from Python code. Running playbook directly or using other callback plugins gives no errors

sivel commented 1 year ago

Duplicate of https://github.com/ansible/ansible-runner/issues/1077

Shrews commented 1 year ago

Closing as duplicate.

gotounix commented 1 month ago

@NitroCao I also have the same problem, how did you fix it?