Hi guys,
I’m trying to use a loop and with_dict together, but I have an issue with the value of some of key are missing, for example the value ‘ssh_key’:
It’s is proposital because i don’t wanna any key in file.
The ‘when’ conditional don’t can evaluate if my variable exists ‘item.value.ssh_key.exists’:
My dict:
users:
user1:
home: “/home/user1”
uid: 5000
gid: 5000
ssh_key: “{{ role_path }}/files/keys/user1.pub”
key_options : ‘from=“192.168.1.2”,no-agent-forwarding,no-port-forwarding,no=X11-forwarding’
user2:
home: “/var/www/user2”
uid: 8000
gid: 8000
key_options : ‘from=“192.168.1.2”,no-agent-forwarding,no-port-forwarding,no=X11-forwarding’
My task:
- name: Configuring authorized_keys
authorized_key:
user : “{{ item.key }}”
key : “{{ lookup(‘file’, ‘{{ item.value.ssh_key }}’) }}”
key_options : “{{ item.value.key_options }}”
with_dict: “{{ users }}”
when: - item.value.ssh_keys.exists == true
Is there some way to make it work properly ?
Thanks!