I'm quite new to Ansible. Using Ansible 2.10 on my laptop (ansible master), and I'm trying to copy some files and directories from a remote serverA to a remote serverB.
In serverA I created an SSH key (id_rsa) using the sudo user, and copied the public key into serverB (into authorized_keys file of the same sudo user).
Hosts file
[servers]
prod_server ansible_host=IP_prod
new_server ansible_host=IP_new
[servers:vars]
ansible_user=sudo_user
ansible_sudo_pass=password
ansible_ssh_private_key_file=~/.ssh/id_rsa
Playbook
- name: Transfer files from prod to new server
hosts: new_server
gather_facts: false
become: true
roles:
- rsync
Role
- name: Copy files to new server
synchronize:
src: /etc/letsencrypt/live/domain/fullchain.pem
dest: /opt
delegate_to: prod_server
Running the playbook an error shows up:
fatal: [new_server -> IP_new]: FAILED! => {"changed": false, "cmd": "/usr/bin/rsync --delay-updates
-F --compress --archive --rsh=/usr/bin/ssh -S none -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no
-o UserKnownHostsFile=/dev/null --rsync-path=sudo rsync --out-format=<<CHANGED>>%i %n%L
/etc/letsencrypt/live/domain/fullchain.pem sudo_user@IP_new:/opt", "msg": "Warning: Identity
file /root/.ssh/id_rsa not accessible: No such file or directory.\nWarning: Permanently added
'IP_new' (ECDSA) to the list of known hosts.\r\nsudo_user@IP_new: Permission denied (publickey).....
Any help would be much appreciated.
Regards