Registering returns to a dictionary attribute

11 views
Skip to first unread message

Tony Yarusso

unread,
Apr 15, 2015, 5:54:40 PM4/15/15
to ansible...@googlegroups.com
So, I have a dictionary variable containing information about all of my users, like this:
user_dictionary:
  bjones:
    realname: Bob Jones
    uniqueid: 1007
    status: active
    notes: Database consultant
 
Part of my playbook changes users' UIDs to make sure they're consistent across all of our systems.  After that happens I want to make sure that the correct user owns things like their mail spool.  However, not every user HAS a mail spool, and I'd like that to be handled gracefully without spitting out any red failure text on playbook run - just skip the task if no mail spool exists.  So, I was thinking I could do something like this:
 
tasks:
- name: Check if mail spools exist
  stat:
    path: "{{ '/var/spool/mail/' ~ item.key }}"
  register: user_dictionary[item.key]["mailspool"]
  with_dict: user_dictionary
- name: Set ownership and permissions of user mail spools
  file:
    path: "{{ '/var/spool/mail/' ~ item.key }}"
    owner: "{{ item.key | lower }}"
    group: "mail"
    mode: "0660"
    state: file
  with_dict: user_dictionary
  when: item.key in getent_passwd and item.key.mailspool.stat.exists
 
But, that register statement isn't working.  There are no mailspool attributes in user_dictionary after running the first task.  Anyone know how to register to a dictionary attribute like that?
Reply all
Reply to author
Forward
0 new messages