I'm working on an Ansible role that can add hosts from a host group to a cluster. However, I'd like to make sure the task doesn't execute if there is only a single host in the group. That way a single node won't attempt to join itself in a cluster. I've used something like this in jinja2 templates before:
{% if var is iterable %}
But is there a way to do this using a "when" statement and a host group? I'm looking for something like this:
task: Join cluster
shell: do the join {{item}}
with_items: "{{ groups['lab'] }}"
when: groups['lab'] is iterable
Solution: when: "groups['lab'] | length > 1"