Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to connect to the host via ssh #20

Closed
chusiang opened this issue May 19, 2017 · 5 comments
Closed

Failed to connect to the host via ssh #20

chusiang opened this issue May 19, 2017 · 5 comments
Assignees

Comments

@chusiang
Copy link
Member

當不使用 ssh key 而是使用 ansible_ssh_passansible_sudo_pass 來處理連線的認證資訊時,有機會遇到 Failed to connect to the host via ssh 的錯誤訊。

Error message:

$ ansible all -m ping
server1 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Control socket connect(/root/.ansible/cp/570a47a2a4): Connection refused\r\nFailed to connect to new control master\r\n",
    "unreachable": true
}

版本資訊:

$ cat /etc/alpine-release
3.4.6

$ ansible --version
ansible 2.3.0.0
  config file = /srv/ansible_playbooks/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Jun 29 2016, 08:57:23) [GCC 5.3.0]
@chusiang
Copy link
Member Author

chusiang commented May 19, 2017

@chusiang chusiang self-assigned this May 19, 2017
@chusiang
Copy link
Member Author

chusiang commented May 19, 2017

我想我知道為什麼了,@William-Yeh 包的 image 沒有安裝 openssh-client,而我一裝起它 Ansible 就會改用 SSH 的方式連接 managed node,而不是透過 paramiko。

或許在 Ansible 2.3 裡,ansible_ssh_pass 只有用 paramike 實作!?可我印象中在 Ansible 2.0 時不曾特別用 -c 來切換 paramiko 模式就可以用了啊。

@chusiang
Copy link
Member Author

哈,果然把 openssh-client 給移除就不需要特別用 -c paramiko 了!

/srv # apk del openssh-client
WARNING: Ignoring APKINDEX.167438ca.tar.gz: No such file or directory
WARNING: Ignoring APKINDEX.a2e6dac0.tar.gz: No such file or directory
(1/1) Purging openssh-client (7.2_p2-r4)
Executing busybox-1.24.2-r13.trigger
OK: 111 MiB in 42 packages

$ ansible all -m ping
server1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

@chusiang
Copy link
Member Author

chusiang commented Jul 6, 2017

附上來自 Python 模塊基礎 | w3cschool 的 paramiko 介紹。

paramiko 是一個用於做遠程控制的模塊,使用該模塊可以對遠程服務器進行命令或文件操作,值得一說的是,fabric 和 ansible 內部的遠程管理就是使用的 paramiko 來實現。

@chusiang
Copy link
Member Author

chusiang commented Aug 22, 2017

If we want to use the ssh mode, not paramiko, we need to setting something like this !

$ vim ./ansible.cfg
[defaults]
hostfile = hosts
transport = ssh
host_key_checking = False

[ssh_connection]
ssh_args =
scp_if_ssh = True

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant