I am following an ansible tutorial and trying to run ad hoc ansible command but I am getting a permission denied error. My controller (local machine) is wsl ubuntu and the node is amazon linux 2023. I used the AWS UI to generate the access keys and I can reach my node via ssh with no issues.
The command I am trying to run is
ansible all -i inventory -m ping
but when I run it, I am getting
ec2-user@ec2-xx-xx-xx-xx.compute-1.amazonaws.com | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ec2-user@ec2-xx-xx-xx-xx.compute-1.amazonaws.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).",
"unreachable": true
}
my inventory file is:
ec2-user@ec2-xx-xx-xx-xx.compute-1.amazonaws.com
ec2-user@ec2-xx-xx-xx-xx.compute-1.amazonaws.com
ec2-user@ec2-xx-xx-xx-xx.compute-1.amazonaws.com
And my ansible.cfg file is:
private_key_file=~/.ssh/path/to/private/key
I've tried moving around where the put the 'private_key_file'. I've had it in the inventory file itself and also in the etc/ansible/ansible.cfg. I still get the same error. I've read that it's a permissions issue but I'm just very lost.