Моя конфигурация Ansible ansible.cfg
:
[defaults]
host_key_checking = False
remote_user = centos
roles_path = ./roles
pipelining = True
[ssh_connection]
ssh_args = -F /etc/ansible/ssh/ssh_config
ssh_config
:
Host bastion.host
Hostname bastion.host
User centos
IdentityFile /etc/ansible/ssh/KEY.pem
StrictHostKeyChecking no
Host 10.*.*.*
User centos
ProxyCommand ssh -W %h:%p bastion.host
IdentityFile /etc/ansible/ssh/KEY.pem
StrictHostKeyChecking no
когда я пытаюсь выполнить пьесу Ansible
ansible -i /etc/ansible/inventories/aws-inventory/ec2.py tag_class_master -m ping
The authenticity of host 'bastion.host' can't be established.
ECDSA key fingerprint is SHA256:vwYBZHWHDXx2ehQTEhzpD4EAcTTnu5cJWsNFPOYt9Q0.
Are you sure you want to continue connecting (yes/no)? The authenticity of host 'bastion.host' can't be established.
ECDSA key fingerprint is SHA256:vwYBZHWHDXx2ehQTEhzpD4EAcTTnu5cJWsNFPOYt9Q0.
Are you sure you want to continue connecting (yes/no)? The authenticity of host 'bastion.host' can't be established.
ECDSA key fingerprint is SHA256:vwYBZHWHDXx2ehQTEhzpD4EAcTTnu5cJWsNFPOYt9Q0.
Are you sure you want to continue connecting (yes/no)? yes
Please type 'yes' or 'no': yes
Please type 'yes' or 'no': yes
Please type 'yes' or 'no': yes
Please type 'yes' or 'no': yes
10.0.1.178 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Host key verification failed.\r\nssh_exchange_identification: Connection closed by remote host\r\n",
"unreachable": true
}
10.0.3.188 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Connection timed out during banner exchange\r\n",
"unreachable": true
}
10.0.2.36 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: Connection timed out during banner exchange\r\n",
"unreachable": true
}
но когда я скопирую ssh_config в домашний каталог ~/.ssh/config
он начинает работать. Я потратил несколько дней на его отладку и пробовал разные решения, например
ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p centos@bastion.host -i /etc/ansible/ssh/KEY.pem"'
в определенных группах хостов. Почему мне нужно поместить файл конфигурации ssh в мой домашний каталог вместо использования ssh_args = -F /etc/ansible/ssh/ssh_config
параметр? Моя доступная версия:
ansible 2.5.1
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.15rc1 (default, Apr 15 2018, 21:51:34) [GCC 7.3.0]
Ansible доцеризован, и я запускаю его как root:
FROM ubuntu:bionic-20180426
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y ansible sshpass python-pip
# install boto python module for ec2 dynamic inventory
RUN pip install boto
ENTRYPOINT /bin/bash
изнутри моего доступного репо, например
docker run -it --rm -v $(pwd):/etc/ansible/ ansible:ubuntu bash
Была такая же ситуация, как и у вас. Я запустил Ansible с -vvvv для отладки SSH и обнаружил, что он ищет ключ внутри root / etc / .ssh. Моя ошибка заключалась в запуске с sudo. Если ваш ключ находится в домашнем каталоге - вы получите эту ошибку.