ansible-community / molecule-libvirt

Molecule LibVirt Provider
https://github.com/ansible-community/molecule-libvirt/issues/13#issuecomment-1372615418
MIT License
35 stars 19 forks source link

ux: authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.manage'"} #21

Closed ssbarnea closed 3 years ago

ssbarnea commented 3 years ago

When libvirt is not yet correctly configured for current user, you will get an error like:

TASK [Create network molecule network] ***********************************************************************************************************************
failed: [localhost] (item=instance) => {"ansible_loop_var": "item", "changed": false, "item": {"name": "instance"}, "msg": "authentication unavailable: no polkit agent available to authenticate action 'org.libvirt.unix.manage'"}

This is usually fixed by running:

usermod --append --groups libvirt `whoami`
# second command is really needed otherwise current session will not get the new groups. 
# it can get even worse when using ssh as even closing the session and restarting it may not work due to ssh connection caching in the client
newgrp libvirt
# i even had to reboot a machine to convince it to list libvirt when running `groups`

Can we do something to make molecule more aware of broken setups and hint the user about ways to fix his environment?

We should add some code inside the driver sanity check method that checks for this and prevent even starting execution of a scenario if libvirt is broken.

jamesregis commented 3 years ago

I have proposed a fix with a pull request.

(venv-mol) [james@e6230 example]$ mol destroy INFO default scenario test matrix: dependency, cleanup, destroy INFO Performing prerun... INFO Added ANSIBLE_ROLES_PATH=~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:../../../../.cache/roles INFO Running default > dependency WARNING Skipping, missing the requirements file. WARNING Skipping, missing the requirements file. INFO Running default > cleanup WARNING Skipping, cleanup playbook not configured. INFO Running default > destroy CRITICAL Current user doesn't belong to libvirt group. Running 'usermod --append --groups libvirt whoami'and 'newgrp libvirt' should fix it.