ansible-collections / community.libvirt

Manage libvirt with Ansible
http://galaxy.ansible.com/community/libvirt
GNU General Public License v3.0
61 stars 40 forks source link

The libvirt module is not importable. Check the requirements #125

Closed IncredibleRichie closed 2 years ago

IncredibleRichie commented 2 years ago
SUMMARY

Since the beginning of the week Ansible dosn´t find the libvirt module on EL8 (Centos8, Rocky8 and Alma8), i did not test other OS in this Case. I did not change anything on my side. The libvirt module is not importable. Check the requirements

ISSUE TYPE
ANSIBLE VERSION
2.12.4-1 ansible-core
5.6.0-1 ansible
COLLECTION VERSION
latest
OS / ENVIRONMENT

Latest Arch linux, targtet=EL8 (CENTOS8, Rocky8 or Alma8)

STEPS TO REPRODUCE

Using the following role https://github.com/stackhpc/ansible-role-libvirt-host.

TASK [stackhpc.libvirt-host : Ensure libvirt storage pools are defined] ********
Tuesday 31 May 2022  08:14:39 +0000 (0:00:00.115)       0:02:16.985 *********** 
failed: [95.216.117.85] (item={'name': 'vm-storage', 'type': 'dir', 'path': '/var/vm-storage', 'mode': 755, 'owner': 'root', 'group': 'root'}) => {"ansible_loop_var": "item", "changed": false, "item": {"group": "root", "mode": 755, "name": "vm-storage", "owner": "root", "path": "/var/vm-storage", "type": "dir"}, "msg": "The `libvirt` module is not importable. Check the requirements."}
EXPECTED RESULTS

Ansible creates a storage for Libvirt

ACTUAL RESULTS

Ansible does not find the libvirt module since the beginning of the week.

csmart commented 2 years ago

Hi @IncredibleRichie thanks for the report! Can I ask how you are accessing the role and collections? I spun up a fresh CentOS Stream 8 VM and it worked for me via the following:

Install deps:

sudo dnf install -y ansible-core
ansible-galaxy install stackhpc.libvirt-host
ansible-galaxy collection install community.general community.libvirt

Ansble version:

$ ansible --version
ansible [core 2.12.5]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/csmart/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /home/csmart/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.12 (default, Sep 21 2021, 00:10:52) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
  jinja version = 2.10.3
  libyaml = True

Playbook:

---
- name: Ensure that Libvirt is configured
  hosts: all
  roles:
    - role: stackhpc.libvirt-host
      libvirt_host_pools:
        - name: my-pool
          type: dir
          capacity: 1024
          path: /tmp/pool
          mode: 755
          owner: my-user
          group: my-group

      libvirt_host_networks:
        - name: brnat-example
          mode: nat
          bridge: brnat-example
          domain: example.local
          ip: 192.168.133.254
          netmask: 255.255.255.0
          dhcp_start: 192.168.133.100
          dhcp_end: 192.168.133.200

Run:

$ ansible-playbook -i localhost, -c local site.yml -b                                                                                                                                                                                                                                                                                                                                                                                                                  

PLAY [Ensure that Libvirt is configured] *******************************************************************************                                                                                                                                                                                                                                                                                                                                                                          

TASK [Gathering Facts] *************************************************************************************************                                                                                                                                                                                                                                                                                                                                                                          
ok: [localhost]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

TASK [stackhpc.libvirt-host : gather os specific variables] ************************************************************                                                                                                                                                                                                                                                                                                                                                                          
ok: [localhost] => (item=/home/csmart/.ansible/roles/stackhpc.libvirt-host/vars/RedHat.yml)                                                                                                                                                                                                                                                                                                                                                                                                       

TASK [stackhpc.libvirt-host : Verify that Virtualization Technology (VT) is enabled] ***********************************                                                                                                                                                                                                                                                                                                                                                                          
ok: [localhost]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

TASK [stackhpc.libvirt-host : Set a fact about whether Virtualization Technology (VT) is enabled] **********************                                                                                                                                                                                                                                                                                                                                                                          
ok: [localhost]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

TASK [stackhpc.libvirt-host : Notify if Virtualization Technology (VT) is disabled] ************************************                                                                                                                                                                                                                                                                                                                                                                          
skipping: [localhost]                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

TASK [stackhpc.libvirt-host : Fail if Virtualization Technology (VT) is disabled] **************************************                                                                                                                                                                                                                                                                                                                                                                          
skipping: [localhost]                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

TASK [stackhpc.libvirt-host : Fail if SASL password is not defined] ****************************************************                                                                                                                                                                                                                                                                                                                                                                          
skipping: [localhost]                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

TASK [stackhpc.libvirt-host : Include install-daemon.yml] **************************************************************                                                                                                                                                                                                                                                                                                                                                                          
included: /home/csmart/.ansible/roles/stackhpc.libvirt-host/tasks/install-daemon.yml for localhost                                                                                                                                                                                                                                                                                                                                                                                                

TASK [stackhpc.libvirt-host : Install custom yum repositories] *********************************************************                                                                                                                                                                                                                                                                                                                                                                          

TASK [stackhpc.libvirt-host : Ensure libvirt packages are installed] ***************************************************                                                                                                                                                                                                                                                                                                                                                                          
changed: [localhost]                                                                                                                                                                                                                                                                                                                                                                                                                                                                              

TASK [stackhpc.libvirt-host : Ensure the EPEL repository is enabled] ***************************************************                                                                                                                                                                                                                                                                                                                                                                          
skipping: [localhost]                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

TASK [stackhpc.libvirt-host : Ensure QEMU emulator packages are installed] *********************************************                                                                                                                                                                                                                                                                                                                                                                          

TASK [stackhpc.libvirt-host : Include install-client.yml] **************************************************************                                                                                                                                                                                                                                                                                                                                                                          
skipping: [localhost]                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

TASK [stackhpc.libvirt-host : Run post-install stage] ******************************************************************                                                                                                                                                                                                                                                                                                                                                                          

TASK [stackhpc.libvirt-host : Include config.yml] **********************************************************************                                                                                                                                                                                                                                                                                                                                                                          
included: /home/csmart/.ansible/roles/stackhpc.libvirt-host/tasks/config.yml for localhost                                                                                                                                                                                                                                                                                                                                                                                                        

TASK [stackhpc.libvirt-host : Create directory for libvirt socket] *****************************************************                                                                                                                                                                                                                                                                                                                                                                          
skipping: [localhost]                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

TASK [stackhpc.libvirt-host : Process lineinfile rules] ****************************************************************                                                                                                                                                                                                                                                                                                                                                                          
skipping: [localhost] => (item={'args': {'path': '/etc/sysconfig/libvirtd', 'insertafter': '^#LIBVIRTD_ARGS=', 'regexp': '^LIBVIRTD_ARGS=', 'line': 'LIBVIRTD_ARGS=""'}, 'condition': False})                                                                                                                                                                                                                                                                                                     

TASK [stackhpc.libvirt-host : Ensure configuration files exist] ********************************************************                                                                                                                                                                                                                                                                                                                                                                          
changed: [localhost] => (item=libvirtd.conf)                                                                                                                                                                                                                                                                                                                                                                                                                                                      
changed: [localhost] => (item=qemu.conf)                                                                                                                                                                                                                                                                                                                                                                                                                                                          

TASK [stackhpc.libvirt-host : Create systemd drop-in directory for socket listen address] ******************************                                                                                                                                                                                                                                                                                                                                                                          

TASK [stackhpc.libvirt-host : Configure socket listen address] *********************************************************                                                                                                                                                                                                                                                                                                                                                                          

TASK [stackhpc.libvirt-host : Create directory for TLS certificates and keys] ******************************************                                                                                                                                                                                                                                                                                                                                                                          

TASK [stackhpc.libvirt-host : Copy TLS certificates and keys] **********************************************************                                                                                                                                                                                                                                                                                                                                                                          
skipping: [localhost] => (item=servercert)                                                                                                                                                                                                                                                                                                                                                                                                                                                        
skipping: [localhost] => (item=serverkey)                                                                                                                                                                                                                                                                                                                                                                                                                                                         
skipping: [localhost] => (item=clientcert)                                                                                                                                                                                                                                                                                                                                                                                                                                                        
skipping: [localhost] => (item=clientkey)                                                                                                                                                                                                                                                                                                                                                                                                                                                         
skipping: [localhost] => (item=cacert)                                                                                                                                                                                                                                                                                                                                                                                                                                                            

TASK [stackhpc.libvirt-host : Ensure libvirt SASL user exists] *********************************************************                                                                                                                                                                                                                                                                                                                                                                          
skipping: [localhost] => (item=None)                                                                                                                                                                                                                                                                                                                                                                                                                                                              
skipping: [localhost]                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

TASK [stackhpc.libvirt-host : Flush handlers] **************************************************************************                                                                                                                                                                                                                                                                                                                                                                          

RUNNING HANDLER [stackhpc.libvirt-host : stop libvirt] *****************************************************************                                                                                                                                                                                                                                                                                                                                                                          
ok: [localhost]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

RUNNING HANDLER [stackhpc.libvirt-host : start libvirtd sockets] *******************************************************                                                                                                                                                                                                                                                                                                                                                                          
ok: [localhost] => (item=libvirtd-tcp.socket)                                                                                                                                                                                                                                                                                                                                                                                                                                                     
ok: [localhost] => (item=libvirtd-tls.socket)                                                                                                                                                                                                                                                                                                                                                                                                                                                     

TASK [stackhpc.libvirt-host : Ensure the libvirt daemon is started and enabled] ****************************************                                                                                                                                                                                                                                                                                                                                                                          
ok: [localhost] => (item=libvirtd-tcp.socket)                                                                                                                                                                                                                                                                                                                                                                                                                                                     
ok: [localhost] => (item=libvirtd-tls.socket)                                                                                                                                                                                                                                                                                                                                                                                                                                                     
changed: [localhost] => (item=libvirtd)                                                                                                                                                                                                                                                                                                                                                                                                                                                           

TASK [stackhpc.libvirt-host : Include client-config.yml] ***************************************************************                                                                                                                                                                                                                                                                                                                                                                          
included: /home/csmart/.ansible/roles/stackhpc.libvirt-host/tasks/client-config.yml for localhost                                                                                                                                                                                                                                                                                                                                                                                                 

TASK [stackhpc.libvirt-host : Ensure client configuration files exist] *************************************************                                                                                                                                                                                                                                                                                                                                                                          

TASK [stackhpc.libvirt-host : Include pools.yml] ***********************************************************************                                                                                                                                                                                                                                                                                                                                                                          
included: /home/csmart/.ansible/roles/stackhpc.libvirt-host/tasks/pools.yml for localhost                                                                                                                                                                                                                                                                                                                                                                                                         

TASK [stackhpc.libvirt-host : Ensure libvirt LVM storage pool directories exist] ***************************************                                                                                                                                                                                                                                                                                                                                                                          
skipping: [localhost] => (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'})                                                                                                                                                                                                                                                                                                                                   

TASK [stackhpc.libvirt-host : include rbd.yml] *************************************************************************                                                                                                                                                                                                                                                                                                                                                                          
skipping: [localhost] => (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'})                                                                                                                                                                                                                                                                                                                                   

TASK [stackhpc.libvirt-host : Ensure libvirt storage pools are defined] ************************************************                                                                                                                                                                                                                                                                                                                                                                          
changed: [localhost] => (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'})                                                                                                                                                                                                                                                                                                                                    

TASK [stackhpc.libvirt-host : Check libvirt directory storage pool status] *********************************************                                                                                                                                                                                                                                                                                                                                                                          
ok: [localhost] => (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'})                                                                                                                                                                                                                                                                                                                                         

TASK [stackhpc.libvirt-host : Ensure libvirt directory storage pools are built] ****************************************                                                                                                                                                                                                                                                                                                                                                                          
changed: [localhost] => (item={'status': 'inactive', 'invocation': {'module_args': {'name': 'my-pool', 'command': 'status', 'uri': 'qemu:///system', 'state': None, 'xml': None, 'autostart': None, 'mode': None}}, 'failed': False, 'changed': False, 'item': {'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'}, 'ansible_loop_var': 'item'})                                                                      

TASK [stackhpc.libvirt-host : Ensure libvirt storage pools are active] *************************************************                                                                                                                                                                                                                                                                                                                                                                          
changed: [localhost] => (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'})                                                                                                                                                                                                                                                                                                                                    

TASK [stackhpc.libvirt-host : Ensure libvirt storage pools are started on boot] ****************************************                                                                                                                                                                                                                                                                                                                                                                          
changed: [localhost] => (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'})                                                                                                                                                                                                                                                                                                                                    

TASK [stackhpc.libvirt-host : Include networks.yml] ********************************************************************                                                                                                                                                                                                                                                                                                                                                                          
included: /home/csmart/.ansible/roles/stackhpc.libvirt-host/tasks/networks.yml for localhost                                                                                                                                                                                                                                                                                                                                                                                                      

TASK [stackhpc.libvirt-host : Ensure libvirt networks are defined] *****************************************************                                                                                                                                                                                                                                                                                                                                                                          
changed: [localhost] => (item={'name': 'brnat-example', 'mode': 'nat', 'bridge': 'brnat-example', 'domain': 'example.local', 'ip': '192.168.133.254', 'netmask': '255.255.255.0', 'dhcp_start': '192.168.133.100', 'dhcp_end': '192.168.133.200'})                                                                                                                                                                                                                                                

TASK [stackhpc.libvirt-host : Ensure libvirt networks are started on boot] *********************************************                                                                                                                                                                                                                                                                                                                                                                          
changed: [localhost] => (item={'name': 'brnat-example', 'mode': 'nat', 'bridge': 'brnat-example', 'domain': 'example.local', 'ip': '192.168.133.254', 'netmask': '255.255.255.0', 'dhcp_start': '192.168.133.100', 'dhcp_end': '192.168.133.200'})                                                                                                                                                                                                                                                

TASK [stackhpc.libvirt-host : Ensure libvirt networks are active] ******************************************************                                                                                                                                                                                                                                                                                                                                                                          
changed: [localhost] => (item={'name': 'brnat-example', 'mode': 'nat', 'bridge': 'brnat-example', 'domain': 'example.local', 'ip': '192.168.133.254', 'netmask': '255.255.255.0', 'dhcp_start': '192.168.133.100', 'dhcp_end': '192.168.133.200'})                                                                                                                                                                                                                                                

PLAY RECAP *************************************************************************************************************                                                                                                                                                                                                                                                                                                                                                                          
localhost                  : ok=22   changed=10   unreachable=0    failed=0    skipped=18   rescued=0    ignored=0                                                                                                                                                                                                                                                                                                                                                                                
IncredibleRichie commented 2 years ago

You´re right it is working on CentOS8 stream.

I just ran your config on ALMA 8 and it did not succeed.

# ansible-playbook -i localhost, -c local test.yaml -b

PLAY [Ensure that Libvirt is configured] *****************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
[WARNING]: Platform linux on host localhost is using the discovered Python interpreter at /usr/bin/python3.8, but future installation of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible-core/2.12/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [stackhpc.libvirt-host : gather os specific variables] **********************************************************************************************************************************************************************************
ok: [localhost] => (item=/root/.ansible/roles/stackhpc.libvirt-host/vars/RedHat.yml)

TASK [stackhpc.libvirt-host : Verify that Virtualization Technology (VT) is enabled] *********************************************************************************************************************************************************
ok: [localhost]

TASK [stackhpc.libvirt-host : Set a fact about whether Virtualization Technology (VT) is enabled] ********************************************************************************************************************************************
ok: [localhost]

TASK [stackhpc.libvirt-host : Notify if Virtualization Technology (VT) is disabled] **********************************************************************************************************************************************************
skipping: [localhost]

TASK [stackhpc.libvirt-host : Fail if Virtualization Technology (VT) is disabled] ************************************************************************************************************************************************************
skipping: [localhost]

TASK [stackhpc.libvirt-host : Fail if SASL password is not defined] **************************************************************************************************************************************************************************
skipping: [localhost]

TASK [stackhpc.libvirt-host : Include install-daemon.yml] ************************************************************************************************************************************************************************************
included: /root/.ansible/roles/stackhpc.libvirt-host/tasks/install-daemon.yml for localhost

TASK [stackhpc.libvirt-host : Install custom yum repositories] *******************************************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Ensure libvirt packages are installed] *************************************************************************************************************************************************************************
ok: [localhost]

TASK [stackhpc.libvirt-host : Ensure the EPEL repository is enabled] *************************************************************************************************************************************************************************
skipping: [localhost]

TASK [stackhpc.libvirt-host : Ensure QEMU emulator packages are installed] *******************************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Include install-client.yml] ************************************************************************************************************************************************************************************
skipping: [localhost]

TASK [stackhpc.libvirt-host : Run post-install stage] ****************************************************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Include config.yml] ********************************************************************************************************************************************************************************************
included: /root/.ansible/roles/stackhpc.libvirt-host/tasks/config.yml for localhost

TASK [stackhpc.libvirt-host : Create directory for libvirt socket] ***************************************************************************************************************************************************************************
skipping: [localhost]

TASK [stackhpc.libvirt-host : Process lineinfile rules] **************************************************************************************************************************************************************************************
skipping: [localhost] => (item={'args': {'path': '/etc/sysconfig/libvirtd', 'insertafter': '^#LIBVIRTD_ARGS=', 'regexp': '^LIBVIRTD_ARGS=', 'line': 'LIBVIRTD_ARGS=""'}, 'condition': False}) 

TASK [stackhpc.libvirt-host : Ensure configuration files exist] ******************************************************************************************************************************************************************************
ok: [localhost] => (item=libvirtd.conf)
ok: [localhost] => (item=qemu.conf)

TASK [stackhpc.libvirt-host : Create systemd drop-in directory for socket listen address] ****************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Configure socket listen address] *******************************************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Create directory for TLS certificates and keys] ****************************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Copy TLS certificates and keys] ********************************************************************************************************************************************************************************
skipping: [localhost] => (item=servercert) 
skipping: [localhost] => (item=serverkey) 
skipping: [localhost] => (item=clientcert) 
skipping: [localhost] => (item=clientkey) 
skipping: [localhost] => (item=cacert) 

TASK [stackhpc.libvirt-host : Ensure libvirt SASL user exists] *******************************************************************************************************************************************************************************
skipping: [localhost] => (item=None) 
skipping: [localhost]

TASK [stackhpc.libvirt-host : Flush handlers] ************************************************************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Ensure the libvirt daemon is started and enabled] **************************************************************************************************************************************************************
ok: [localhost] => (item=libvirtd-tcp.socket)
ok: [localhost] => (item=libvirtd-tls.socket)
ok: [localhost] => (item=libvirtd)

TASK [stackhpc.libvirt-host : Include client-config.yml] *************************************************************************************************************************************************************************************
included: /root/.ansible/roles/stackhpc.libvirt-host/tasks/client-config.yml for localhost

TASK [stackhpc.libvirt-host : Ensure client configuration files exist] ***********************************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Include pools.yml] *********************************************************************************************************************************************************************************************
included: /root/.ansible/roles/stackhpc.libvirt-host/tasks/pools.yml for localhost

TASK [stackhpc.libvirt-host : Ensure libvirt LVM storage pool directories exist] *************************************************************************************************************************************************************
skipping: [localhost] => (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'}) 

TASK [stackhpc.libvirt-host : include rbd.yml] ***********************************************************************************************************************************************************************************************
skipping: [localhost] => (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'}) 

TASK [stackhpc.libvirt-host : Ensure libvirt storage pools are defined] **********************************************************************************************************************************************************************
failed: [localhost] (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'}) => {"ansible_loop_var": "item", "changed": false, "item": {"capacity": 1024, "group": "my-group", "mode": 755, "name": "my-pool", "owner": "my-user", "path": "/tmp/pool", "type": "dir"}, "msg": "The `libvirt` module is not importable. Check the requirements."}

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
localhost                  : ok=11   changed=0    unreachable=0    failed=1    skipped=18   rescued=0    ignored=0   

ansible --version
ansible [core 2.12.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.12 (default, Apr 21 2022, 07:55:08) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10)]
  jinja version = 2.10.3
  libyaml = True
csmart commented 2 years ago

@IncredibleRichie I tested this on AlmaLinux 8. I think the problem is that the Ansible version installed from EPEL has a dependency on Python 3.8 (which is pulled in automatically):

$ ansible --version |grep "python version"
  python version = 3.8.12 (default, Apr 21 2022, 07:55:08) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10)]

However, the python3-libvirt package is for 3.6 only:

$ rpm -ql python3-libvirt |grep libvirt.py$
/usr/lib64/python3.6/site-packages/libvirt.py

This means that when running Ansible, it can't find the libvirt module as it's not in the Python path. It works in CentOS Stream 8, because the system version of Python is 3.8 which matches Ansible.

I think you need EPEL to create a Python 3.8 version of the python3-libvirt package, or maybe try using pip to install a version of Ansible which will use your 3.6 system Python.

$ python3 --version
Python 3.6.8

$ which ansible
/usr/bin/which: no ansible in (/home/csmart/.local/bin:/home/csmart/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin)

$ python3 -m pip install --user --upgrade pip setuptools wheel
Cache entry deserialization failed, entry ignored
Collecting pip
  Using cached https://files.pythonhosted.org/packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl
Collecting setuptools
  Using cached https://files.pythonhosted.org/packages/b0/3a/88b210db68e56854d0bcf4b38e165e03be377e13907746f825790f3df5bf/setuptools-59.6.0-py3-none-any.whl
Collecting wheel
  Using cached https://files.pythonhosted.org/packages/27/d6/003e593296a85fd6ed616ed962795b2f87709c3eee2bca4f6d0fe55c6d00/wheel-0.37.1-py2.py3-none-any.whl
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-21.3.1 setuptools-59.6.0 wheel-0.37.1

$ python3 -m pip install --user --upgrade ansible
Collecting ansible
  Using cached ansible-4.10.0-py3-none-any.whl
Collecting ansible-core~=2.11.7
  Using cached ansible_core-2.11.12-py3-none-any.whl
Requirement already satisfied: jinja2 in /usr/lib/python3.6/site-packages (from ansible-core~=2.11.7->ansible) (2.10.1)
Requirement already satisfied: PyYAML in /usr/lib64/python3.6/site-packages (from ansible-core~=2.11.7->ansible) (3.12)
Collecting packaging
  Using cached packaging-21.3-py3-none-any.whl (40 kB)
Collecting resolvelib<0.6.0,>=0.5.3
  Using cached resolvelib-0.5.4-py2.py3-none-any.whl (12 kB)
Requirement already satisfied: cryptography in /usr/lib64/python3.6/site-packages (from ansible-core~=2.11.7->ansible) (3.2.1)
Requirement already satisfied: six>=1.4.1 in /usr/lib/python3.6/site-packages (from cryptography->ansible-core~=2.11.7->ansible) (1.11.0)
Requirement already satisfied: cffi!=1.11.3,>=1.8 in /usr/lib64/python3.6/site-packages (from cryptography->ansible-core~=2.11.7->ansible) (1.11.5)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib64/python3.6/site-packages (from jinja2->ansible-core~=2.11.7->ansible) (0.23)
Collecting pyparsing!=3.0.5,>=2.0.2
  Using cached pyparsing-3.0.9-py3-none-any.whl (98 kB)
Requirement already satisfied: pycparser in /usr/lib/python3.6/site-packages (from cffi!=1.11.3,>=1.8->cryptography->ansible-core~=2.11.7->ansible) (2.14)
Installing collected packages: pyparsing, resolvelib, packaging, ansible-core, ansible
Successfully installed ansible-4.10.0 ansible-core-2.11.12 packaging-21.3 pyparsing-3.0.9 resolvelib-0.5.4

$ which ansible
~/.local/bin/ansible

$ ansible --version |grep -E "core|python version"
ansible [core 2.11.12] 
  python version = 3.6.8 (default, Apr 29 2022, 13:46:02) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10)]

$ ansible-playbook -i localhost, -c local site.yml -b
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Apr 29 2022, 13:46:02) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10)]. This feature will be removed 
from ansible-core in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

PLAY [Ensure that Libvirt is configured] *****************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
[WARNING]: Platform linux on host localhost is using the discovered Python interpreter at /usr/bin/python3.6, but future installation of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible-core/2.11/reference_appendices/interpreter_discovery.html for more information.
ok: [localhost]

TASK [stackhpc.libvirt-host : gather os specific variables] **********************************************************************************************************************************************************************************
ok: [localhost] => (item=/home/csmart/.ansible/roles/stackhpc.libvirt-host/vars/RedHat.yml)

TASK [stackhpc.libvirt-host : Verify that Virtualization Technology (VT) is enabled] *********************************************************************************************************************************************************
ok: [localhost]

TASK [stackhpc.libvirt-host : Set a fact about whether Virtualization Technology (VT) is enabled] ********************************************************************************************************************************************
ok: [localhost]

TASK [stackhpc.libvirt-host : Notify if Virtualization Technology (VT) is disabled] **********************************************************************************************************************************************************
skipping: [localhost]

TASK [stackhpc.libvirt-host : Fail if Virtualization Technology (VT) is disabled] ************************************************************************************************************************************************************
skipping: [localhost]

TASK [stackhpc.libvirt-host : Fail if SASL password is not defined] **************************************************************************************************************************************************************************
skipping: [localhost]

TASK [stackhpc.libvirt-host : Include install-daemon.yml] ************************************************************************************************************************************************************************************
included: /home/csmart/.ansible/roles/stackhpc.libvirt-host/tasks/install-daemon.yml for localhost

TASK [stackhpc.libvirt-host : Install custom yum repositories] *******************************************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Ensure libvirt packages are installed] *************************************************************************************************************************************************************************
ok: [localhost]

TASK [stackhpc.libvirt-host : Ensure the EPEL repository is enabled] *************************************************************************************************************************************************************************
skipping: [localhost]

TASK [stackhpc.libvirt-host : Ensure QEMU emulator packages are installed] *******************************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Include install-client.yml] ************************************************************************************************************************************************************************************
skipping: [localhost]

TASK [stackhpc.libvirt-host : Run post-install stage] ****************************************************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Include config.yml] ********************************************************************************************************************************************************************************************
included: /home/csmart/.ansible/roles/stackhpc.libvirt-host/tasks/config.yml for localhost

TASK [stackhpc.libvirt-host : Create directory for libvirt socket] ***************************************************************************************************************************************************************************
skipping: [localhost]

TASK [stackhpc.libvirt-host : Process lineinfile rules] **************************************************************************************************************************************************************************************
skipping: [localhost] => (item={'args': {'path': '/etc/sysconfig/libvirtd', 'insertafter': '^#LIBVIRTD_ARGS=', 'regexp': '^LIBVIRTD_ARGS=', 'line': 'LIBVIRTD_ARGS=""'}, 'condition': False}) 

TASK [stackhpc.libvirt-host : Ensure configuration files exist] ******************************************************************************************************************************************************************************
ok: [localhost] => (item=libvirtd.conf)
ok: [localhost] => (item=qemu.conf)

TASK [stackhpc.libvirt-host : Create systemd drop-in directory for socket listen address] ****************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Configure socket listen address] *******************************************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Create directory for TLS certificates and keys] ****************************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Copy TLS certificates and keys] ********************************************************************************************************************************************************************************
skipping: [localhost] => (item=servercert) 
skipping: [localhost] => (item=serverkey) 
skipping: [localhost] => (item=clientcert) 
skipping: [localhost] => (item=clientkey) 
skipping: [localhost] => (item=cacert) 

TASK [stackhpc.libvirt-host : Ensure libvirt SASL user exists] *******************************************************************************************************************************************************************************
skipping: [localhost] => (item=None) 
skipping: [localhost]

TASK [stackhpc.libvirt-host : Flush handlers] ************************************************************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Ensure the libvirt daemon is started and enabled] **************************************************************************************************************************************************************
ok: [localhost] => (item=libvirtd-tcp.socket)
ok: [localhost] => (item=libvirtd-tls.socket)
changed: [localhost] => (item=libvirtd)

TASK [stackhpc.libvirt-host : Include client-config.yml] *************************************************************************************************************************************************************************************
included: /home/csmart/.ansible/roles/stackhpc.libvirt-host/tasks/client-config.yml for localhost

TASK [stackhpc.libvirt-host : Ensure client configuration files exist] ***********************************************************************************************************************************************************************

TASK [stackhpc.libvirt-host : Include pools.yml] *********************************************************************************************************************************************************************************************
included: /home/csmart/.ansible/roles/stackhpc.libvirt-host/tasks/pools.yml for localhost

TASK [stackhpc.libvirt-host : Ensure libvirt LVM storage pool directories exist] *************************************************************************************************************************************************************
skipping: [localhost] => (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'}) 

TASK [stackhpc.libvirt-host : include rbd.yml] ***********************************************************************************************************************************************************************************************
skipping: [localhost] => (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'}) 

TASK [stackhpc.libvirt-host : Ensure libvirt storage pools are defined] **********************************************************************************************************************************************************************
ok: [localhost] => (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'})

TASK [stackhpc.libvirt-host : Check libvirt directory storage pool status] *******************************************************************************************************************************************************************
ok: [localhost] => (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'})

TASK [stackhpc.libvirt-host : Ensure libvirt directory storage pools are built] **************************************************************************************************************************************************************
skipping: [localhost] => (item={'status': 'active', 'invocation': {'module_args': {'name': 'my-pool', 'command': 'status', 'uri': 'qemu:///system', 'state': None, 'xml': None, 'autostart': None, 'mode': None}}, 'failed': False, 'changed': False, 'item': {'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'}, 'ansible_loop_var': 'item'}) 

TASK [stackhpc.libvirt-host : Ensure libvirt storage pools are active] ***********************************************************************************************************************************************************************
ok: [localhost] => (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'})

TASK [stackhpc.libvirt-host : Ensure libvirt storage pools are started on boot] **************************************************************************************************************************************************************
ok: [localhost] => (item={'name': 'my-pool', 'type': 'dir', 'capacity': 1024, 'path': '/tmp/pool', 'mode': 755, 'owner': 'my-user', 'group': 'my-group'})

TASK [stackhpc.libvirt-host : Include networks.yml] ******************************************************************************************************************************************************************************************
included: /home/csmart/.ansible/roles/stackhpc.libvirt-host/tasks/networks.yml for localhost

TASK [stackhpc.libvirt-host : Ensure libvirt networks are defined] ***************************************************************************************************************************************************************************
ok: [localhost] => (item={'name': 'brnat-example', 'mode': 'nat', 'bridge': 'brnat-example', 'domain': 'example.local', 'ip': '192.168.133.254', 'netmask': '255.255.255.0', 'dhcp_start': '192.168.133.100', 'dhcp_end': '192.168.133.200'})

TASK [stackhpc.libvirt-host : Ensure libvirt networks are started on boot] *******************************************************************************************************************************************************************
ok: [localhost] => (item={'name': 'brnat-example', 'mode': 'nat', 'bridge': 'brnat-example', 'domain': 'example.local', 'ip': '192.168.133.254', 'netmask': '255.255.255.0', 'dhcp_start': '192.168.133.100', 'dhcp_end': '192.168.133.200'})

TASK [stackhpc.libvirt-host : Ensure libvirt networks are active] ****************************************************************************************************************************************************************************
ok: [localhost] => (item={'name': 'brnat-example', 'mode': 'nat', 'bridge': 'brnat-example', 'domain': 'example.local', 'ip': '192.168.133.254', 'netmask': '255.255.255.0', 'dhcp_start': '192.168.133.100', 'dhcp_end': '192.168.133.200'})

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
localhost                  : ok=19   changed=1    unreachable=0    failed=0    skipped=19   rescued=0    ignored=0   
IncredibleRichie commented 2 years ago

Thanks a lot, I didn't consider that Python3-libvirt is only available for 3.6, thanks for finding out!!!

darksong1165 commented 5 months ago

I got this issue again on Debian 12 even though python3-libvirt should support Python versions >=3.11 now. Ansible (2.16.4) was installed via pipx using Python version 3.11.2. Wasn't there a patch for libvirt?