Unable to execute the shell command at remote server (another server) using ansible script/shell ; even added public key of remote server to ssh

  • name: run emcli commands on the remote server
    hosts: dbhosts
    become: yes
    become_user: oracle

    tasks:

    • name: run emcli login and logout
      shell |
      sudo ssh oracle@remote_server << EOF
      echo “Hello”
      EOF

Hi @Madan_Kumar_Dusarlap

I don’t think using the ansible.builtin.shell module to execute tasks on target hosts that establish SSH connections to remote servers is the right strategy.

Ansible Connection
Ansible Inventory

Attempting an SSH connection during playbook execution could lead to issues that are external to Ansible.

I can assume that this approach stems from the fact that remote_server is not directly reachable from the control node.

Perhaps the best solution would be to configure a jump host to connect to remote_server.

Something like this :

[remote]
remote_server ansible_host=REMOTE_IP ansible_ssh_common_args='-o ProxyJump=jumphost_user@jumphost'