Unable to execute playbook via ansible-runner in an executable environment: Inventory Parsing failed

Project structure

.
├── README.md
├── ansible.cfg
├── appstack
├── artifacts
├── env
├── inventory
├── project
└── tests

my inventory is just a simple localhost setting:

all:
  children:
    ungrouped:
      hosts:
        localhost:

and a host_vars directory:

inventory/host_vars/localhost.yml

which has the following information:

ansible_host: 127.0.0.1
ansible_connection: local

I have downloaded the ghcr.io/ansible-community/community-ee-base:latest image to try out the Process Execution logic with the following command:

ansible-runner . \
--process-isolation \
--process-isolation-executable=docker \
--container-image=ghcr.io/ansible-community/community-ee-base:latest \
-p stack_generate.yml -vvv

This throws out the following error while trying to parse the inventory:

ansible-playbook [core 2.16.1]
  config file = /runner/ansible.cfg
  configured module search path = ['/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.12/site-packages/ansible
  ansible collection location = /runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.12.0 (main, Oct  2 2023, 00:00:00) [GCC 13.2.1 20230918 (Red Hat 13.2.1-3)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
Using /runner/ansible.cfg as config file
host_list declined parsing /runner/inventory/hosts as it did not pass its verify_file() method
script declined parsing /runner/inventory/hosts as it did not pass its verify_file() method
auto declined parsing /runner/inventory/hosts as it did not pass its verify_file() method
Parsed /runner/inventory/hosts inventory source with yaml plugin
redirecting (type: callback) ansible.builtin.yaml to community.general.yaml
ERROR! Unexpected Exception, this is probably a bug: type 'NoneType' is not an acceptable base type
the full traceback was:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/ansible/cli/__init__.py", line 659, in cli_executor
    exit_code = cli.run()
                ^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/ansible/cli/playbook.py", line 156, in run
    results = pbex.run()
              ^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/ansible/executor/playbook_executor.py", line 119, in run
    self._tqm.load_callbacks()
  File "/usr/local/lib/python3.12/site-packages/ansible/executor/task_queue_manager.py", line 200, in load_callbacks
    self._stdout_callback = callback_loader.get(self._stdout_callback)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/ansible/plugins/loader.py", line 864, in get
    return self.get_with_context(name, *args, **kwargs).object
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/ansible/plugins/loader.py", line 899, in get_with_context
    self._module_cache[path] = self._load_module_source(resolved_type_name, path)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/ansible/plugins/loader.py", line 837, in _load_module_source
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 994, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/runner/artifacts/f92e5701-a06c-4931-b849-504ab81812df/callback/awx_display.py", line 316, in <module>
    class CallbackModule(DefaultCallbackModule):
TypeError: type 'NoneType' is not an acceptable base type

locally ansible-inventory -i inventory --list infact parses the correct inventory.

Why is it failing to parse the inventory in the container?

It turns out it might due to the redirecting callback plugin. I had set ANSIBLE_STDOUT_CALLBACK: yaml which I guess the community-ee base image might not have (the community.general collection might not be installed) upon commenting this the value out from my env/envvars file I was able to get the playbook running.

2 Likes

Yes, community-ee-base does not contain community.general. See images/execution-environments at main · ansible-community/images · GitHub.

You don’t need the community.general.yaml callback for YAML output though, you can also use the default callback and tell it to emit YAML: ansible.builtin.default callback – default Ansible screen output — Ansible Community Documentation

2 Likes

That is strange, as you mentioned I adapted:

ansible.cfg

[defaults]
stdout_callback = yaml
callback_result_format = yaml

but the execution does not give a YAML output:

ansible-playbook [core 2.16.1]
  config file = /runner/ansible.cfg
  configured module search path = ['/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.12/site-packages/ansible
  ansible collection location = /runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.12.0 (main, Oct  2 2023, 00:00:00) [GCC 13.2.1 20230918 (Red Hat 13.2.1-3)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
Using /runner/ansible.cfg as config file
Skipping callback 'awx_display', as we already have a stdout callback.
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: debug.yml ************************************************************
1 plays in debug.yml

PLAY [all] *********************************************************************

TASK [ping from ee] ************************************************************
task path: /runner/project/debug.yml:5
ok: [localhost] => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": false, "ping": "pong"}
ok: [sd-rxi2-66370581] => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "changed": false, "ping": "pong"}

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

I also tried adding ANSIBLE_CALLBACK_RESULT_FORMAT: yaml in the env/envvars file but the output still goes through with JSON formatting

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.