Failed to import the required Python library (librouteros)

Hello,
I’m trying to use community.routeros.api for the first time. I’m using a venv in which I installed ansible. Hopefully, I correctly updated community.routeros to 3.19.0. in it.
When running a simple task involving community.routeros.api module, I’ve got:

[ERROR]: Task failed: Module failed: Failed to import the required Python library (librouteros)

Any idea ?

Best regards

You need to install the Python librouteros library:

Into the venv:

Also if you’re using a venv, you need to make sure that modules are actually using the venv. IIRC ansible-core doesn’t do that automatically when running modules against localhost.

I don’t know how I overlooked this librouteros requirement, thinking it belonged to community.routeros modules.
I feel a bit stupid now.

Thank you very much for replying: after installing librouter with pip, it now works ok.

@felixfontein
Thank you for replying. Can you elaborate a bit ?

Now I’m using ansible this way:

source /path/to/venv/bin/activate
ansible localhost -i hosts.yml -m include_role -a “name=whatever”

It seems to work.
How can I check the behaviour you warned about ?

If you install the module requirements (librouteros) also in that venv, Ansible modules running for localhost might not find that library because they are not running in the context of the venv.

If you installed librouteros in the venv (and not globally), you can try to run one of the API based modules and see whether it works. If it complains about missing librouteros, you will have to point Ansible to the venv somehow. If it runs (and maybe complains about something else, depending on your use), everything’s fine :slight_smile: