Non-existing group resulted in error.

  • name: task
    debug: msg=“I will fail”
    when: inventory_hostname in groups[‘doesnotexist’]

fatal: [host] => error while evaluating conditional: inventory_hostname in groups[‘doesnotexist’]

I’m assuming this is not expected behavior? Running Ansible 1.9.2, if it’s not, I’ll be happy to file a bug.

Regards,
Nico

I for one expect it to fail, what were you expecting?

It to ignore the fact that this group doesn’t exist within this playbook/inventory for the sake of re-usability of the role.

Maybe you could look at ignore_error ?

Ignoring errors is hardly ever the correct way of dealing with things.

Anyway, for those interested, the obvious fix is to check whether the group you are looking for is in the current list of groups instead of checking whether the nodename is in a specific group, so instead of:

inventory_hostname in groups

do a

x in group_names