kushaldas / qubes_ansible

Ansible module and connection plugin for Qubes OS
https://qubes-ansible.readthedocs.io/en/latest/index.html
GNU General Public License v3.0
10 stars 5 forks source link

Detect if a VM is fedora or debian #13

Open micahflee opened 6 years ago

micahflee commented 6 years ago

The createinventory command makes a nice inventory file of all VMs. However this means it breaks updates.yaml example because all templates are in a single group, instead of in separate fedora_templates and debian_templates groups. This is also true for standalone VMs.

How would I go about writing a task that first detects the OS of a host in the inventory, then does one thing if it's fedora and something else if it's debian?

micahflee commented 6 years ago

Or perhaps, maybe a better way to do this, is to make the createinventory command do the detection of VM type and split them into groups based on that time. Like, perhaps it can create these groups:

This way, it would be easy to write a playbook that automatically updates all fedora and debian templates and standalone VMs just by using those specific groups (and ignoring the other groups).

I think maybe in order to do this, the createinventory command may need to power on VMs and run commands in them to detect their OS... it could save some time with the templates by deciding any template with "fedora" in its name is fedora, and any template with "debian" or "whonix" in it's name is debian. But then any other templates, or any standalones, would need to be powered on and to run something like which dnf and which apt-get to detect their package managers.

kushaldas commented 6 years ago

Or perhaps, maybe a better way to do this, is to make the createinventory command do the detection of VM type and split them into groups based on that time. Like, perhaps it can create these groups:

What about a second command for this detailed inventory file? @micahflee

micahflee commented 6 years ago

Like, createinventory stays the same, and createdetailedinventory splits your templates and standalones into groups based on their OS? I like that idea.

kushaldas commented 6 years ago

Also booting up all the vms (every kind) and detecting OS will be time consuming. I want to propose the following flow to make it fast.

This way things will be still fast enough for the end user while creating the inventory file.

@micahflee @mig5 Your thoughts?

mig5 commented 6 years ago

I think that makes sense. Ultimately the goal is to add the distro to each VM, and then collate a list of VMs of type 'template' or 'standalone' grouped by their distro flag ('feature' as you call it).

Whichever way makes sense to do that in the most Pythonic/Ansible-ish way, suits me :)

You could also group appVMs by distro (not sure how useful, but if you can come up with a generic way of grouping by distro and VM type, might as well throw it into the inventory)

sayanchowdhury commented 6 years ago

Manual sounds like the way to go, if human-error does not turn critical.

kushaldas commented 6 years ago

A way to make is fast is by giving another command in Ansible module, at first it will create a file in the local directory with the existing VM names and any tag/feature value (best case basis).

The user can then fill up the file, and rerunning the ansible command will apply those values to the VMs.

This way, the user has to type one command twice, much easier than total manual work :)