Hey folks,
As part of a legacy situation I have a bunch of ansible playbooks that I would to run against nixos targets. Specifically, I have one that starts a docker container on the target via docker compose. I can start the container using the compose file directly on the nixos target, so that works. However, when I run the ansible playbook remotely pointing at my nixos target, I get an error:
─ ansible-playbook -i inventory.yaml test_nixos.yaml ─╯
PLAY [media] ****************************************************************************************
TASK [Gathering Facts] ******************************************************************************
[WARNING]: Platform linux on host mb is using the discovered Python interpreter at /run/current-
system/sw/bin/python3.11, but future installation of another Python interpreter could change the
meaning of that path. See https://docs.ansible.com/ansible-
core/2.15/reference_appendices/interpreter_discovery.html for more information.
ok: [mb]
TASK [speedtest] ************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'requests'
fatal: [mb]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (Docker SDK for Python: docker>=5.0.0 (Python >= 3.6) or docker<5.0.0 (Python 2.7)) on mb's Python /run/current-system/sw/bin/python3.11. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter, for example via `pip install docker` (Python >= 3.6) or `pip install docker==4.4.4` (Python 2.7). The error was: No module named 'requests'"}
...ignoring
PLAY RECAP ******************************************************************************************
mb : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1
I tried adding some packages to my configuration.nix
environment.systemPackages = [
pkgs.python3
pkgs.ansible
pkgs.python311Packages.ansible
pkgs.python311Packages.pip
pkgs.python311Packages.requests
];
But no joy. I guess that ansible can’t install the required python packages when it ssh’s into the target?
Thanks in advance