Allow and skip empty loop

Hi! I would like to have an task that would delete groups
ONLY if the variable have a content …

so i have an delete_users_groups.yml:

Writing delete_groups: like that it mean empty string type.

So you need to write like delete_groups: as empty list type.

Use the filter *default*

  loop: "{{ delete_groups | default(, true) }}"

See:
https://jinja.palletsprojects.com/en/3.1.x/templates/#jinja-filters.default

Optionally, use the module *ansible.utils.validate*
See:
https://docs.ansible.com/ansible/latest/collections/ansible/utils/validate_module.html