Using a conditional (when) in conjunction with a loop

65 views
Skip to first unread message

Alex King

unread,
May 27, 2014, 5:43:51 PM5/27/14
to ansible...@googlegroups.com
Currently I add system users with the following play:

#
# Create system users
#
- name: sys admin users
tags: sys_admin_users
user: name={{ userdef[item].name }} uid={{ userdef[item].uid }} "groups={{ system_admins_groups|join(',') }}" "comment={{ userdef[item].comment }}" password={{ userdef[item].password }} update_password=on_create shell=/bin/bash
with_items: system_admins

userdef is a dictionary containing all users' details. system_admins is
a list of system admin users.

I'd prefer to have userdefs as a list and be able to write this as
something like:

- name: sys admin users
tags: sys_admin_users
user: name=item.name uid=item.uid "groups={{ system_admins_groups|join(',') }}" "comment={{ item.comment }}" password=item.passwordupdate_password=on_create shell=/bin/bash
with_items: userdef
when: item.name in system_admins

Mixing with_items and when doesn't currently seem possible. (Ansible 1.5.3)

Cheers,
Alex

James Cammarata

unread,
May 28, 2014, 12:21:39 AM5/28/14
to ansible...@googlegroups.com
I'm unclear why you can't do this? Is it failing with an error or some other problem?




--
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+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5385070C.7020503%40king.net.nz.
For more options, visit https://groups.google.com/d/optout.

Michael DeHaan

unread,
May 28, 2014, 8:00:45 AM5/28/14
to ansible...@googlegroups.com
Same question as James, but just wanted to point out the 1.6 series is now available.




To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAMFyvFjJDO8-yudFfQ_DAZw9bBmnusnrV_GrmZNyvPGbitN0BA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages