Hello all,
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:
[root@admin oort]# cat roles/ON4_project_managment/vars/users.yml
---
users_account:
user username:
status: new
login_name: testuser
main_group_name: natalie-alpha
secondary_groups:
type_authentication: core
mail: 'Email="test1mail"'
telf: 'Telf="
6123456789"'
role: 'role="admin"'
user_info: 'user_info="researcher"'
start_date: 'start_date="2015/12/13"'
end_date: 'end_date="2016/12/13"'
network:
acl:
user2 username2:
status: new
login_name: testuser2
main_group_name: natalie-alpha
secondary_groups:
- group1
- oneadmin
- SGE
type_authentication: core
mail: 'Email="test2@mail"'
telf: 'Telf="465465465"'
role: 'role="admin"'
user_info: 'user_info="researcher"'
start_date: 'start_date="2015/11/13"'
end_date: 'end_date="2016/11/13"'
network:
acl:
Then, in the playbook I read the list and also the secondary groups to assign the secondary groups to the user. My problem is that it can happen that the user does not belong to any secondary group like in the users.yml example file from above so right now, if this happens, I get this error:
TASK: [ON4_project_managment | Assign the secondary groups for the user] ******
fatal: [m-opennebula4] => the key secondary_groups should point to a list, got 'None'
But I would like that the task is only executed when the user has some secondary group assigned.
This is the task (right now it it is just simplefied with "echo" but it is the same approach:
- name: Assign the secondary groups for the user
sudo: True
sudo_user: oneadmin
shell: echo {{ item.0.login_name }};echo {{ item.1 }}
with_subelements:
- users_account
- secondary_groups
when: item.1 is defined
tags:
- Assign_secondary_group
- esteban
I have been playing with != none or !="" or is defined but I always get the error :( .. Probably, I am not understanding it correctly and I am sure some of you already needed to face this issue, so I would appreciate your help :)
I hope I have explained myself correctly because I am a bit tired right now :/
Thanks in advance,
Esteban