test host for group membership

Here's one way (assuming 0.8 syntax). Just have two short plays
that talk to each group, and use the group-exclusion features.

hosts: virt:!virt-managed
tasks:
    - template: ...

hosts: virt-managed
tasks:
     - template: ...

(Alternatively, create a group called virt-unmanaged, and make the
group virt contain those other two groups as child groups)

You can then, in other steps before or after, address the virt group
as a whole. Playbooks can contain as many plays as you want
so it's fine to use different hosts selectors.

I think lots of people end up getting carried away with "only_if" as a
conditional check, and that's ok, but it's usually not neccessary.
I'll leave it someone else to post the only_if version :slight_smile:

Another method -- perhaps nicer, perhaps not, is to set a default
variable for the "virt" group using a "group_vars/virt" file in a
location relative to the playbook.

Set another variable in "group_vars/virt_managed".

The more specific group will override the other.

Let's say it was $filepath

Then just do src=$filepath/foo.conf

This allows for one playbook.