Run task only if host does not belong to a group

Question:

I’d like to able to run an ansible task only if the host of the current playbook does not belong to a certain group. In semi pseudo code:

How should I do this?

Answer:

Here’s another way to do this:

group_names is a magic variable as documented here: https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html :

group_names is a list (array) of all the groups the current host is in.

Leave a Reply