Reputation: 23
I am attempting to deploy ssh keys with ansible using a file lookup task that utilizes {{ item.key }} which is simply a username and I am trying to find the appropriate syntax to call for the lookup value.
# Deploy Key Task
- name: add user ssh keys
authorized_key:
user={{ item.key }}
key={{ lookup('file', 'files/{{ item.key }}.pub') }}
with_dict: users
Where users is
users:
example:
state: present
comment: "Example User"
shell: "/bin/bash"
uid: 5001
gid: 5001
From the dictionary, I am wanting to use item.key to populate the user.pub file.
Within the files directory I simply have a file called example.pub with the users public key.
Blockquote
Upvotes: 0
Views: 4608
Reputation: 23
Did some digging and this is what solved it.
- name: add user ssh keys
authorized_key:
user={{ item.key }}
key="{{ lookup('file', 'files/'+ item.key +'.pub') }}"
with_dict: users
Note: key="{{ lookup('file', 'files/'+ item.key +'.pub') }}"
Upvotes: 2