Normally we will add the private key of the server in our .ssh/authorized keys, right?
But i want to keep the ssh key in a different location.
I created a folder called "centos" and i am planning to keep all the ansible files related to this project under this folder.
/Users/shivinvijai/Desktop/Learnings/Ansible/centos
In this folder, I fist created an inventory file.
shivinvijai@Shivins-MacBook-Pro centos % cat inventory
[myservers]
150.61.189.96 ansible_user=opc ansible_ssh_private_key_file=/Users/shivinvijai/Desktop/Learnings/Ansilbe/ssh-key-2023-01-01.key
shivinvijai@Shivins-MacBook-Pro centos %
I specify my username and path to the ssh key file.
Now, I going to do a test, here i am using my own inventory file so the command will be this
shivinvijai@Shivins-MacBook-Pro centos % ansible -i inventory -m ping myservers
150.61.189.96 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}