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:
- name: my command
command: echo stuff
when: "if {{ ansible_hostname }} not in {{ ansible_current_groups }}"
How should I do this?
Here's another way to do this:
group_names
is a magic variable as documented here: http://docs.ansible.com/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts :You can set a control variable in vars files located in
group_vars/
or directly in hosts file like this:And run tasks like this: