How to use ansible authorized_key to authorize a ServerA (not the controller machine) to access Server B.
Scenario: Need a playbook to execute from a ansible controller that should append id_rsa.pub of a specific user from a remote ssh ServerA (no the controller machine ) to ServerB.
In our case the ServerA count is 20 while ServerB count is 200. What i have tried so far and failed.
---
# tasks file for passwordless
- name: Play to setup Passowrdless
hosts: destnode
remote_user: "{{ ssh_user }}"
vars_prompt:
- name: "ssh_user"
prompt: "Please specify ssh user name"
private: no
tasks:
- name: Copy pub key from SourceNode to Destnode
authorized_key:
user: "{{ ssh_user }}"
state: present
key: "{{ lookup('file', lookup('env','HOME') + '/.ssh/id_rsa.pub') }}"
become: yes
become_user: "{{ ssh_user }}"
delegate_to: "{{ hostvars.sourcenode }}"
when: ssh_user is defined
register: copyout
- name: Print copyout value
debug:
msg: "{{ copyout }}"