Ansible always has SSH error against localhost? - ansible

On a CentOS machine, I can ssh into localhost. I can also successfully "sudo ansible -m ping localhost". Port 22 is also open. I can also run a playbook against localhost where "connetion : local".
However, when trying to do anything against localhost via ansible with SSH, I get the following:
localhost | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n",
"unreachable": true
}
As far as I can tell, the other similar SO answer to a similar error here
does not really solve the problem as it basically says "well don't SSH then".

Related

Issue with connection established from ansible to windows

WinRM service is already running on this windows machine, but when I run my playbook against a Windows node I'm getting below error.
error:
fatal: [xx:xx:xx:xxx]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh_exchange_identification: Connection closed by remote host", "unreachable": true}
Could you please let me know if anything is missing or incorrect
Regards,
Priya P
As Zeitounator said:
Add winrm connection details. Ie. if you have an ini inventory with a windows group: (put the credentials in a vault)
[windows:vars]
ansible_user=<from vault>
ansible_password=<from vault>
ansible_connection=winrm
ansible_winrm_server_cert_validation=ignore
ansible_port=5986
#ansible_port=5985
ansible_winrm_transport=ntlm
ansible_winrm_scheme=https
#ansible_winrm_scheme=http

SSH permission denied for ec2 using Ansible

I am new to Ansible and was tring to figure out how to establish a ssh connection via ansible.
I have created an ec2 instance(Linux) and i have controlling node as my local machine(Ubuntu).
Now, I have generated and added key from my local to remote instance. I am also able to ssh by running ssh ec2-user#.
But, when doing the same using ansible command
ansible -i hosts all -m ping -u ec2-user
I am getting error as:
ec2-user#13.127.222.56 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ec2-user#13.127.222.56: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).",
"unreachable": true
}
My hosts file is:
[test]
13.127.222.56
Now, I am unable to figure out how to work with this further. I am missing some authentication required by ansible because this usually comes only when ssh is unable to get the key.

How to connect with ansible to an EC2 instance?

Friends,
I am trying to run some ansible tasks against an EC2 instance and getting the following error:
fatal: [ubuntu]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to
the host via ssh: ssh: connect to host 34.218.130.84 port 22:connection timed out",
"unreachable": true}
I think, the problem is related to Ansible configuration because I tryed connecting with the instance via Putty using the same IP, username and pem-file and it worked just fine.
This is how my inventory file looks like:
[brt]
ubuntu ansible_ssh_host=34.218.130.84
ansible_ssh_private_key_file=/home/mjgoncalves/ansible/chave/aws-ansible.pem
[brt:vars]
ansible_ssh_private_key_file=/home/mjgoncalves/ansible/chave/aws-ansible.pem
ansible_ssh_host=34.218.130.84
ansible_ssh_user=username
ansible_ssh_pass=passowrd
ansible_become=yes
ansible_become_method=sudo
ansible_become_pass=password
ansible_connection=ssh
...
Any idea what I may be missing?
The "ssh" in the variable names has been deprecated. You should use ansible_host instead of ansible_ssh_host (same for username, password etc., but not for the ansible_ssh_private_key_file).
The IP in the message (connect to host 34.228.140.94) is not the same as in your inventory, so it seems that it does not take the IP from the variable, or you are overwriting it somewhere else.

Ansible for Windows

I am trying to set up my ansible host to connect to windows. However ping is failing with the following error:
sudo ansible win -m win_ping
hostname | UNREACHABLE! => {
"changed": false,
"msg": "basic: HTTPConnectionPool(host='hostname', port=5986): Read timed out. (read timeout=30)",
"unreachable": true
}
pywinrm is installed on my linux box and WinRM is installed on the windows box.
Hosts file:
[win]
systemname
[win:vars]
ansible_user=username
ansible_password=passord
ansible_connection=winrm
ansible_winrm_scheme=http
ansible_winrm_server_cert_validation=ignore
ansible_winrm_transport=basic
Appreciate any advice.
Thanks.
Disabling the Windows Firewall (Domain, private and public networks) in the Windows box, fixed the issue for me.
Can you double check the WinRM Listener settings:
winrm enumerate winrm/config/Listener
If the output is what you expect, can you test a command on the local server as shown here:
winrs -r:http://server:5985/wsman -u:Username -p:Password ipconfig
Ansible has a good reference on this topic as well.

Ansible "Failed to connect to host via ssh: Permission denied" when trying -m ping all

I've been at this all morning, and I've seen multiple posts about this error in other places, but none of the solutions seem to be working for me at this point.
I'm playing around with Ansible and trying to setup my inventory + hosts for this project.
For my hosts file I have (/etc/ansible/hosts):
[test-servers]
x.x.x.x
For my inventory I have (/etc/ansible/inventory.txt):
ansible-target ansible_ssh_host=x.x.x.x ansible_user=user ansible_ssh_pass=password
But when I try to run ansible -m ping all I get:
x.x.x.x | UNREACHABLE! => {
"changed": false,
"msg": Failed to connect to the host via ssh: user#x.x.x.x: Permission denied (publickey,password,keyboard-interacgive.\r\n"
"unreachable":true
}
However, I get a pong response successfully when I run:
ansible x.x.x.x -m ping -i /etc/ansible/inventory.txt
Anyone have any idea what this might be?
Thanks in advance.
Found the solution. Needed to have it prompt me for a password to setup the initial Ansible SSH configuration.
Ansible: Permission denied (publickey, password)

Resources