I have a bare-bones Ansible (2.16.8) playbook that I’m trying to run for all hosts in an inventory group, but it doesn’t seem to be working correctly. It always seems to work for at least one host, sometimes two, but never for all of them. I’ve also noticed that, when I try to run it on more than one host it asks for my passphrase 1-5 times, pauses after each host until I hit enter, then shows the others as unreachable, permission denied (full output below):
Failed to connect to the host via ssh: [email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
Failed to connect to the host via ssh: [email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
If I replace the group name with any of the individual hosts it runs fine, but trying to run more than one causes the problem. I can also ssh into all of them with the key I’m using.
My inventory file looks something like this:
dev:
hosts:
host1:
ansible_host: 1.2.3.4
host2:
ansible_host: 1.2.3.5
host3:
ansible_host: 1.2.3.6
host4:
ansible_host: 1.2.4.4
east:
hosts:
host1:
host2:
host3:
vars:
ansible_ssh_private_key_file: "/path/to/key"
ansible_user: auser
and this is the playbook I’m trying to run to test with:
---
- name: Test
hosts:
east
tasks:
- name: Ping
ansible.builtin.ping:
I suspect whatever is causing the pause between hosts may be the problem, but I don’t know where to look to see what is causing the pause. I’ve tried running with -vvv but haven’t been able to find anything that looks obviously wrong there either. It almost acts like it’s running all of the connections at the same time and they’re interfering with one another.
Just to clarify, the playbook runs on any of the hosts individually, I just can’t get it to run for more than one at a time.
Here is an example of the full output for one attempt to run the group. The ssh passphrase was entered at each prompt and enter had to be hit to continue after each response (3 extra times, once after each “fatal: [hostxx]” message and once after the “ok: [hostxx]” message):
ansible-playbook pingtest.yml -i inventory.yml
PLAY [Test] ***************************************************************************************************************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************************************************************************************************
Enter passphrase for key '/home/auser/.ssh/a_servers':
Enter passphrase for key '/home/auser/.ssh/a_servers':
fatal: [host1]: UNREACHABLE! => {
"changed": false,
"unreachable": true
}
MSG:
Failed to connect to the host via ssh: [email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
Enter passphrase for key '/home/auser/.ssh/a_servers':
[WARNING]: Platform linux on host host2 is using the discovered Python interpreter at /usr/bin/python3.6, but future installation of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible-core/2.16/reference_appendices/interpreter_discovery.html for more information.
ok: [host2]
Enter passphrase for key '/home/auser/.ssh/a_servers':
Enter passphrase for key '/home/auser/.ssh/a_servers':
fatal: [host3]: UNREACHABLE! => {
"changed": false,
"unreachable": true
}
MSG:
Failed to connect to the host via ssh: [email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
TASK [Ping] ***************************************************************************************************************************************************************************************************************
ok: [host2]
PLAY RECAP ****************************************************************************************************************************************************************************************************************
host1 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
host2 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
host3 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
When attempting to run the playbook multiple times, the successful host seems random, it isn’t always the same host that succeeds.