Writing delete_groups: like that it mean empty string type.

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


Le 03/04/2024 à 11:11, Adrian Sevcenco a écrit :


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:
---
delete_groups:

delete_users:

####
and an users_task.yml with

- name: Delete groups on nodes
ansible.builtin.group:
name: "{{ group_del_name }}"
state: absent
loop_control:
loop_var: group_del_name
loop: "{{ delete_groups }}"

and a playbook with:

---
- hosts: "{{ target | default('all') }}"
gather_facts: False
vars_files:
- "{{ playbook_dir }}/../additions/users/user_group_info.yml"
- "{{ playbook_dir }}/../additions/users/delete_users_groups.yml"

tasks:
- include_tasks: tasks/users_task.yml


The error that i receive is:
Invalid data passed to 'loop', it requires a list, got this instead: None. Hint: If you passed a list/dict of just one element, try adding wantlist=True to your lookup invocation or use q/query instead of lookup.

i tried to add wantlist = True and i got
template error while templating string: expected token 'end of print statement', got '='. String: {{ delete_groups, wantlist=True }}

Any idea how can the loop pe skiped if the target of the loop is empty?

Thanks a lot!
Adrian
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAOL4_EXP6xjdOsxKmB_%3D3dQa41B3kdRdR%3DLutuJab0wsxr4PJw%40mail.gmail.com <https://groups.google.com/d/msgid/ansible-project/CAOL4_EXP6xjdOsxKmB_%3D3dQa41B3kdRdR%3DLutuJab0wsxr4PJw%40mail.gmail.com?utm_medium=email&utm_source=footer>.

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/80005a87-0428-4a5d-b44d-f6569db2c6c5%40tsgri13.fr.

Reply via email to