我使用Ansible和Vagrant。但是,我正在手动运行我的剧本。 Ansible总是在第一次运行时失败:
ansible-playbook -i cluster_hosts site.yml --tags setup_db --limit slave1
报告:
PLAY [database] ***************************************************************
GATHERING FACTS ***************************************************************
fatal: [slave1] => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue
TASK: [postgresql | Copy source list] *****************************************
FATAL: no hosts matched or all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/home/robe/site.retry
slave1 : ok=0 changed=0 unreachable=1 failed=0
我又跑了,它过去了。为什么ansible与第一个失败?
更新
使用 -vvvv 选项
运行PLAY [database] ***************************************************************
GATHERING FACTS ***************************************************************
<192.168.1.13> ESTABLISH CONNECTION FOR USER: vagrant
<192.168.1.13> REMOTE_MODULE setup
<192.168.1.13> EXEC ['sshpass', '-d7', 'ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/home/robe/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'StrictHostKeyChecking=no', '-o', 'GSSAPIAuthentication=no', '-o', 'PubkeyAuthentication=no', '-o', 'User=vagrant', '-o', 'ConnectTimeout=10', '192.168.1.13', "/bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1411394566.34-255722526667010 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1411394566.34-255722526667010 && echo $HOME/.ansible/tmp/ansible-tmp-1411394566.34-255722526667010'"]
fatal: [slave1] => SSH encountered an unknown error. The output was:
OpenSSH_6.2p2 Ubuntu-6ubuntu0.5, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: auto-mux: Trying existing master
debug1: Control socket "/home/robe/.ansible/cp/ansible-ssh-192.168.1.13-22-vagrant" does not exist
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.1.13 [192.168.1.13] port 22.
debug2: fd 3 setting O_NONBLOCK
debug1: connect to address 192.168.1.13 port 22: Connection timed out
ssh: connect to host 192.168.1.13 port 22: Connection timed out
TASK: [postgresql | Copy source list] *****************************************
FATAL: no hosts matched or all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/home/robe/site.retry
slave1 : ok=0 changed=0 unreachable=1 failed=0
答案 0 :(得分:2)
您是否使用包含自定义广告资源文件的专用网络?可能有时虚拟机网络在附加适配器上尚未完全运行。 (vagrant使用默认值并认为一切都在线)
一个简单的解决方法是增加超时时间:
ansible.raw_arguments = ['--timeout=300']
答案 1 :(得分:0)
您尝试使用ansible配置的计算机不接受/正在侦听SSH,或者您遇到网络问题。这是输出的关键部分:
ssh: connect to host 192.168.1.13 port 22: Connection timed out
目标框是否正在运行sshd?