I’ve tried the following code:
`
- name: ensure users exist.
when: item.value.state is defined
user:
state: “{{ item.value.state }}”
name: “{{ item.value.username }}”
comment: “{{ item.value.fullname }}”
password: “{{ item.value.crypted_pass }}”
createhome: “yes”
home: “{{ item.value.home|default(/home/{{ item.value.username }}) }}”
shell: “{{ item.value.shell }}”
uid: “{{ item.value.uid }}”
with_dict: “{{ aspects_local_users }}”
tags: - aspects_local_users
`
Basically, if aspects_local_users.user.home is set, I want to use that value. Otherwise I want to use /home/.
As I expected, you can’t nest {{ }} to get the value out of item.value.username. I, obviously, can get the value if I just do this:
home: "{{ blah|default(item.value.username) }}"
But that leaves off the /home.
Note, I can just create a second task and run one when item.value.home is defined and the other when it isn’t. But I would like to just use one task.
Thanks for any ideas or suggestions!
I’m on Ansible 2.3.2.0 installed from Pip. Ubuntu 16.04 64bit. Testing against vagrant vms.