Add usb support to libvirt-vm role #95
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi
This PR adds functionality to pass through USB devices from Host to VM. I appreciate in a datacenter environment with many VMs this use case may be minimal but can still be a handy option to have for the VMs. As such I have made it transparent and skip over if there is not any usb_devices defined.
I have also tried to follow the style and logic of this role in the way you use includes and generate vars for the additional USB parts.
This has been tested with ansible without any usb_devices defined (skips tasks and is otherwise "transparent"), along with a combination of 1 and 2 USB devices with no errors. I have not tested if there is an upper limit for USB devices presented to a machine. Documentation for upper limit in KVM is a bit sparse. Happy to add an assert or validation if a limit is found. I would hope most users want only a couple of devices to present to VMs
The main thing to be aware about is that Libvirt will complain if the devices are not present when the machine XML is generated - This is noted in the commit for the REAMDE.
Therefore to use the same approach as pre validating the network config with the include to task check-interface.yml, I have an include to check-usb-devices.yml which will validate the USB config before the VM XML task is generated / run. I have had to ignore errors for the output of lsusb and then present the "error" in a bit more of a user friendly message.
Happy to adjust this PR to match your requirements if there is anything else that may need changed otherwise hope you approve this PR and we can get the USB functionality added to the role in a new release.
Many thanks for this role - It works well for my requirements at home
Gavin