Skip to content

Instantly share code, notes, and snippets.

@flrichar
Last active January 17, 2024 22:21
Show Gist options
  • Save flrichar/ea30f03a89a7e656896d1df99659593e to your computer and use it in GitHub Desktop.
Save flrichar/ea30f03a89a7e656896d1df99659593e to your computer and use it in GitHub Desktop.
Libvirt/Virsh Adhoc Ansible Inventory

Dynamic AdHoc Ansible Inventory

  • domain names need to match ssh host ids
  • dynamic inventory ansible module for community.libvirt.libvirt requires qemu-ga running in guest
  • why not just create a temporary ad-hoc inventory of currently running vms?
  • use as an alias or function or with Taskfile, prevent Task from throwing an error for non-running vms
echo "[running]" $(virsh list --name) | xargs printf "%s\n" > ~/.local/tmp/inventory

ansible -i ~/.local/tmp/inventory -a 'uptime' running
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment