--- # ============================================================================= # Libvirt/KVM Dynamic Inventory Configuration # ============================================================================= # Configuration for community.libvirt.libvirt dynamic inventory plugin # Documentation: ansible-doc -t inventory community.libvirt.libvirt # ============================================================================= plugin: community.libvirt.libvirt # Hypervisor Connection # ----------------------------------------------------------------------------- # URI to connect to libvirt hypervisor # Remote SSH connection to grokbox hypervisor uri: 'qemu+ssh://grok@grok.home.serneels.xyz/system' # Inventory Hostname Format # ----------------------------------------------------------------------------- # How to register VMs as inventory hostnames # Options: 'name' (use VM name) or 'uuid' (use UUID) inventory_hostname: name # Grouping Configuration # ----------------------------------------------------------------------------- # Automatically create groups based on VM characteristics compose: # Extract IP address from guest_info interface data ansible_host: >- guest_info['if.1.addr.0.addr'] if 'if.1.addr.0.addr' in guest_info else (guest_info['if.0.addr.0.addr'] if 'if.0.addr.0.addr' in guest_info and guest_info['if.0.addr.0.addr'] != '127.0.0.1' else omit) groups: # Group by VM state (from info dict) running_vms: info.state == 'running' stopped_vms: info.state != 'running' # Group by resource allocation (convert KB to MB) small_vms: (info.memory_kb | int / 1024) <= 2048 medium_vms: (info.memory_kb | int / 1024) > 2048 and (info.memory_kb | int / 1024) <= 8192 large_vms: (info.memory_kb | int / 1024) > 8192 # Group all discovered VMs as kvm_guests kvm_guests: true # Keyed Groups # ----------------------------------------------------------------------------- # Create dynamic groups based on host variables keyed_groups: - key: info.state prefix: state separator: "_" - key: guest_info['os.id'] | default('unknown') prefix: os separator: "_" # Filters # ----------------------------------------------------------------------------- # Set strict mode for error handling strict: false