Member-only story
Ansible | How do I connect with Remote to run my script for Automation
Can I connect to remote server?
After I while since I started using Ansible, when I came back to use it again for running a script from my local machine to remote server, the first thing I wanted to test is can I connect to remote server?
This article will help you to get started with it. Let’s install ansible via pip -
python3 -m pip install --user ansible
I am installing the ansible under my local user folder, ansible executable will be under $HOME/.local/bin, you may need to modify .bashrc to include it in your path.
Now, ansible is installed, let’s try ssh connection using ping module.host_name_or_ip is what you need to replace with along with user. It will ask for password.
ansible all -i host_name_or_ip, -c ssh -u user -k -m ping
Oh it has failed with error
| FAILED! => {
"msg": "to use the 'ssh' connection type with passwords or pkcs11_provider, you must install the sshpass program"
}
Let’s install sshpass and run it again
sudo apt install sshpass
And it has failed again
| FAILED! => {
"msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this. Please add this host's fingerprint to your known_hosts file to manage this host."
}