csmart / ansible-role-virt-infra

Define and manage guests and networks on a KVM host with Ansible
GNU General Public License v3.0
67 stars 48 forks source link

kvmhost[0] breaks multi-host inventories #37

Closed sluetze closed 3 years ago

sluetze commented 3 years ago

Hi again :-),

i have a inventory with multiple kvmhosts

kvmhost:
  hosts:
    host0:
    [...]
    host1:
    [...]

they are also member of another inventory file, for the "which" (Following guidelines @ https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html#intro-patterns)

prod:
  hosts:
    host1:
dev:
  hosts:
    host0:

this results in errors, if i use the role for the prod environment since there is a ton of hostvars[groups['kvmhost'][0]] lookups throughout the role and kvmhost[0] is host0. which just does not exist in dev. This also invalidates the checks for any multi kvmhost scenario. I think there should be very small issues when removing most of the lookups and just use the named facts you register.

Since this makes a whopping 140 occurences of that pattern i am not sure if the role was ever intended to do multiple kvm hosts and if a PR implementing this would be welcomed?

csmart commented 3 years ago

Hey :-) hmmm yeah I'll need to think about this a bit, I wasn't planning on supporting lots of kvm hosts at once as it was really just for dev work. I guess you could just run the same playbook twice with two different kvmhosts?

sluetze commented 3 years ago

yes host-rotation is possible. That's how i solve it atm. It might make sense for my usecase to switch to another role, which fits my usecase better.

csmart commented 3 years ago

I'm happy to make it work if we can find a nice way to do it... :-) We need to match the guests to each kvmhost and then I guess each task probably needs a delegate to the matching kvmhost or something...