2017-08-27 80 views
0

我安裝了ansible(與vagrant)並試圖在Ansible上執行我的第一個遠程shell腳本。我無法用可靠的方法ping主機。但如果我直接ping服務器,我能夠。即使我可以使用我的NIS帳戶登錄遠程服務器,在主機文件中提到。無法ping通遠程服務器,但能夠連接

有人能幫我找到,我在配置中錯過了什麼嗎?

[email protected]:~$ cat /etc/ansible/hosts 
# web 
web1 ansible_host=tomcat-serv-adm1 ansible_connection=ssh ansible_user=username ansible_ssh_pass=password 

[email protected]:~$ ansible web1 -m ping 
web1 | UNREACHABLE! => { 
    "changed": false, 
    "msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: (umask 77 && mkdir -p \"` echo ~/.ansible/tmp/ansible-tmp-1503856866.42-230229170728730 `\" && echo ansible-tmp-1503856866.42-230229170728730=\"` echo ~/.ansible/tmp/ansible-tmp-1503856866.42-230229170728730 `\"), exited with result 2", 
    "unreachable": true 
} 

[email protected]:~$ ping tomcat-serv-adm1 
PING tomcat-serv-adm1-e1000g1.waypoint.com (192.168.66.116) 56(84) bytes of data. 
64 bytes from tomcat-serv-adm1-e1000g1.waypoint.com (192.168.66.116): icmp_req=1 ttl=250 time=22.5 ms 
64 bytes from tomcat-serv-adm1-e1000g1.waypoint.com (192.168.66.116): icmp_req=2 ttl=250 time=19.5 ms 
64 bytes from tomcat-serv-adm1-e1000g1.waypoint.com (192.168.66.116): icmp_req=3 ttl=250 time=17.5 ms 
^C 
--- tomcat-serv-adm1-e1000g1.waypoint.com ping statistics --- 
3 packets transmitted, 3 received, 0% packet loss, time 2003ms 
rtt min/avg/max/mdev = 17.554/19.891/22.562/2.064 ms 
 
[email protected]:~$ ansible -vvv web1 -m ping 
Using /etc/ansible/ansible.cfg as config file 
META: ran handlers 
Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/system/ping.py 
ESTABLISH SSH CONNECTION FOR USER: None 
SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/vagrant/.ansible/cp/d37e71f71a tomcat-serv-adm1 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"'' 
(255, '', 'Permission denied (gssapi-keyex,gssapi-with-mic,publickey,password,keyboard-interactive).\r\n') 
web1 | UNREACHABLE! => { 
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: Permission denied (gssapi-keyex,gssapi-with-mic,publickey,password,keyboard-interactive).\r\n", 
    "unreachable": true 
} 
[email protected]:~$ 
+0

你能ssh到tomcat- SERV-ADM1? Ansible的「ping」模塊不使用「ping」命令。 –

+0

是的,我可以用命令「ssh username @ tomcat-serv-adm1」ssh進入tomcat-serv-adm1。提供密碼後,我可以進入服務器。 – user3183426

回答

0

查看錯誤消息:

考慮更換爲在\根 「/ TMP \」

的路徑在ansible.cfg遠程臨時路徑Ansible的ping不使用ping命令。相反,它會嘗試使用ssh連接到主機。檢查ssh連接。那時,它也創造在目錄remote_tmp一些臨時文件在你ansible.cfg配置文件(默認:/etc/ansible/ansible.cfg)

要解決這個問題:

  1. 編輯您的ansible.cfg和尋找remote_tmp
  2. 確保遠程主機上的目錄是由SSH用戶
  3. 寫如果你不能使其可寫,值更改爲一個目錄,任何人都可以寫(如:/tmp

首先檢查:

$ grep remote_tmp /etc/ansible/ansible.cfg 
remote_tmp  = $HOME/.ansible/tmp 

如果你不能使remote_tmp可寫,在ansible.cfg將值改爲:

remote_tmp  = /tmp/.ansible/tmp 

remote_tmp  = /tmp/.ansible-${USER}/tmp 
+0

我沒有/etc/ansible/ansible.cfg 我可以創建它作爲新的,但我需要在這個? – user3183426

+0

這是默認的。你能發佈'ansible -vvv web1 -m ping'的輸出嗎? – helloV

+0

由於這裏的字符限制,我編輯了原文並添加了詢問詳細信息 – user3183426

相關問題