Ansible community.libvirt module looking for binary in /urs/bin

Hello everyone.

I made the switch from Debian to NixOS recently. I am a big fan of the ethos and the goal and I want to learn how to use it and contribute to writing documentation and tutorials on my blog. I have finished said blog but want to do some infrastructure preparation for deploying it.

I am going to host my blog on a RaspberryPi 5 SBC. Unfortunately I can’t put on NixOS on it, otherwise I would not need to do what I am trying to do now. What I am trying to do now is use Ansible to do automatic provisioning in case I install a routine update that bricks my RP 5 again.

I have enabled virt-manager as per the link here and also did the libvirt setup as per the link here. I created a nix-shell as shown below:

{
  description = "A development environment for running Ansible and libvirt";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };
        pythonWithLibvirt = pkgs.python3.withPackages(ps: [
          ps.libvirt # Add the libvirt Python bindings here
        ]);
      in
      {
        devShells.default = pkgs.mkShell {
          name = "ansible-shell";

          # Packages whose binaries you want available on your PATH.
          packages = with pkgs; [
            ansible
            pythonWithLibvirt
          ];

        };
      }
    );
}

When I do the task list_vms from the Ansible libvirt module, I get the below error:

“msg”: “libvirtError: Cannot check QEMU binary /usr/bin/qemu-system-x86_64: No such file or directory”

I have been trying to use AI, dive into the code bases and try stuff for a week and can’t figure it out.

I have found that the error is thrown here but I don’t know how to explore C code bases and don’t know how the binary variable is set there.

The executable qemu-system-x86_64 is in the PATH both inside the shell and outside the shell.

I have also tryied running the command virsh -c qemu:///system list --all. That runs with no problem at all.

Any help would be appreciated. Thank you for your attention.

I’d try to run the playbook in verbose and see what exactly it is trying to call. Maybe there is an environment variable that is being checked before trying the hard coded paths.

Otherwise you could hack something with systemd to tmpfiles.d to put the binary in the wanted location in a more or less declarative manner.

The error was actually coming from the definition phase.

When I initially set up my Ansible roles, I created a VM manually then exported it’s definition as an XML and after a bit of removing stuff and templating I used thereafter for automatic provisioning. That XML template contained the line <emulator>/usr/bin/qemu-system-x86_64</emulator> This overwrote the automatic detection mechanism.

Tools are working fine and I am on to my next error. Hopefully this one does not take a week.

Thank you for the response and the suggestions. temp files and systemd sounds interesting but I don’t know what it means, do you have some reading material I can go through to learn? In terms of putting the binary in the expected place I don’t think I can do that. I don’t think I can put things in /usr/bin on NixOS. Unless I am wrong? I am quite new to this.

The NixOS option for tmpfiles.d can be found here: NixOS Search

For the syntax the manpages are great at explaining it.

Another example with putting python in /usr/libexec: How to install all pre-requisites for ansible to run on a NixOS system? - #2 by robsliwi

Does this help to get you started?

Yes, I think that’s enough to get me started. Thank you !