Non-existing group resulted in error.

27 views
Skip to first unread message

Nico K.

unread,
Aug 4, 2015, 4:44:49 PM8/4/15
to Ansible Project
- 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

Brian Coca

unread,
Aug 4, 2015, 5:00:01 PM8/4/15
to Ansible Project
I for one expect it to fail, what were you expecting?




--
Brian Coca

Nico K.

unread,
Aug 5, 2015, 1:35:27 AM8/5/15
to Ansible Project
It to ignore the fact that this group doesn't exist within this playbook/inventory for the sake of re-usability of the role.

R. Dikkes

unread,
Aug 5, 2015, 9:25:31 AM8/5/15
to Ansible Project
Maybe you could look at ignore_error ?

Nico K.

unread,
Aug 17, 2015, 9:38:13 AM8/17/15
to Ansible Project
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[x]

do a

x in group_names
Reply all
Reply to author
Forward
0 new messages