Python project integration with Ansible API. After upgrading Ansible from 2.14 to 2.15, playbook execution failed

Background:
We used Ansible’s Python API to execute Playbook, but recently Ansible is preparing to upgrade from 2.14 to 2.15. When executing Playbook, there will be an error message: No module named \ "Ansible_collections. Ansible. builtin ".
I found during debugging that the difference between 2.14 and 2.15 is that Ansible was not loaded_ Builtin_ Runtime.yml file. I would like to ask everyone how to solve this problem

Here is the code:
playbook = PlaybookExecutor(playbooks=playbook_path,
inventory=inventory,
variable_manager=variable_manager,
loader=loader,
passwords=passwords
)

    result = playbook.run()

Are you using ansible-runner? That’s the only public API for running playbooks I’m aware of. If you are using internals of ansible-core you should switch to using ansible-runner.

@jack Did you get any fix for the this issue No module named “ansible_collections.ansible.builtin” ? I am facing the exact same error using PlaybookExecutor. Though I am aware of using public API but just wondering if you found solution for this.

I think you now need to explicitly initialize the plugin loader by calling init_plugin_loader(): Add support for importlib.resources (#78915) · ansible/ansible@56d1423 · GitHub

1 Like

@felixfontein Thanks for the pointers. This worked as a workaround.