I am using ansible for automate the users creation in one of our tools so I have the following users file in vars with the user’s info and also, the user can have some secondary groups assigned besides the main group:
Unfortunatelly, I cannot try it until Monday but I will let you know if it works. Also, I understand that I must set up secondary_groups: in the user.yml file situated on the vars directory when an user does not have secondary groups assigned, right? or am I understand it wrong?
On Monday, I will try to declare secondary_groups: [] and I will also try put this conditional when: item.1 != “” because I only want that the action/command is just executed when secondary_groups really contains some secondary groups to assign to the users.
I tried what you said, I declared secondary groups variable as secondary_groups: [] in the users.yml file at the vars directory and then, on the main file for the task, I just defined when: (item.1 != “”) and indeed, action is only executed when the secondary groups were assigned for the user and if the user does not have any secondary group assigned it does not do anything, what it is expected.
actually, you won't be hitting that when condition, when with_ detects
an empty list it just skips the task. the when: is redundant and would
actually fail as there is no item.1 defined.