I’m trying to use Ansible to copy keys from multiple hosts to a remote host user’s authorized_key file. In my inventory, I have a collectors group and receiver group, as follows:
[collectors]
c1
c2
c3
[receiver]
r1
I want to copy the ssh key from each host in the collectors group to the authorized_key file of user1 in the receiver group. I know I should user the authorized_key module, but I’m stuck on how to generate the “key” directive so it contains all the keys from the collectors group.
- hosts: receiver
tasks:
- name: copy collectors group keys to authorized_keys file
authorized_key:
user: user1
key: ????? (not sure what to use here)
exclusive: yes
I’m looking for some help to properly set the “key” value, or if there is some completely different and better way to accomplish my goal, please share. Thanks!