ansible-plugin
ansible-plugin copied to clipboard
Failed to connect to the host via ssh: Host key verification failed
Describing the Issue I created a basic ansible ping playbook to test the ansible-playbook module in rundeck. I installed the ansible package on the rundeck server as well.
Basic Ansible Ping Playbook stored in /srv/ansible-playbooks/ inside rundeck server.
---
- hosts: all
tasks:
- name: test connection to server
ping:
I created a job called connection-test in rundeck and pointed to the correct playbook. Job Definition:
Ansible Playbook Workflow Node Step. Runs an Ansible Playbook
Ansible base directory path: /srv/ansible-playbooks/
Playbook: ping.yaml
My Rundeck detail
- Rundeck version: [3.0.8]
- install type: [choose: deb]
- OS Name/version: [ubuntu 18.04]
This is what i expect:
ansible-playbook ping.yaml -i hosts
PLAY [all] *************************************************************************************************
TASK [Gathering Facts] *************************************************************************************
ok: [192.168.1.6]
TASK [test connection to server] ***************************************************************************
ok: [192.168.1.6]
PLAY RECAP *************************************************************************************************
192.168.1.6 : ok=2 changed=0 unreachable=0 failed=0
Error Message
When I run this comand: su rundeck -s /bin/bash -c "ansible all -m ping"
16:18:21 | PLAY [all] *********************************************************************
-- | --
16:18:21 |
16:18:21 | TASK [Gathering Facts] *********************************************************
16:18:21 | fatal: [192.168.1.6]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Host key verification failed.\r\n", "unreachable": true}
16:18:21 | to retry, use: --limit @/srv/ansible-playbooks/ping.retry
16:18:21 |
16:18:21 | PLAY RECAP *********************************************************************
16:18:21 | 192.168.1.6 : ok=0 changed=0 unreachable=1 failed=0
16:18:21 |
16:18:21 | Failed: AnsibleNonZero: ERROR: Ansible execution returned with non zero code.
Executing su rundeck -s /bin/bash -c "ansible all -m ping"
as root will work.
I know it's an old issue, but it's still open so maybe it helps someone. There's a difference between 'su' and 'su -'. The first one switches the user, but not the environment. The latter is swtiching both, that can make a big difference! In this case, the user's root directory stays /root and is not switched to ~rundeck. Which makes ssh use the ssh keys of user root, not the rundeck user.