0

I set up 2 new users with their respective key pairs,.. their public keys ve been established on the remote host. The problem am having is I passsed the ssh keys on the host file as follows

[remotehost:var] ansible_ssh_private_key_file=~/.ssh/user1.private_key ansible_ssh_private_key_file=~/.ssh/user2.private_key

The problem is only one user could establish ansible connection. Even tho both users can ssh into the remote host.

Am sure there’s a way set both users up to reach thesame node in the host file

1 Answers1

0

When the users are different on the node running Ansible, you might drop the user name from the base name of the file: ~/.ssh/remotehost.private_key The path is passed to ssh, and ~ is resolved to their personal home directory.

When same local user needs to connect to multiple different remote users, can make "fake" hosts in inventory with different connection vars. ini format:

[remotehost]
remotehostuser1 ansible_user=user1 ansible_ssh_private_key_file=~/.ssh/user1.private_key
remotehostuser2 ansible_user=user2 ansible_ssh_private_key_file=~/.ssh/user2.private_key


[remotehost:vars]
ansible_host=remotehost

More ways to do this exist. Making use of the environment var way of providing a private_key_file, ${ANSIBLE_PRIVATE_KEY_FILE} Or using ssh_config.

John Mahowald
  • 30,009
  • 1
  • 17
  • 32