vagrant - Ansible 在第一次运行时总是失败

标签 vagrant ansible

我使用 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  

最佳答案

您是否使用带有自定义 list 文件的专用网络?有时,虚拟盒网络可能在附加适配器上尚未完全运行。 (vagrant使用默认的,认为一切都在线)

一个简单的解决方法是增加超时:

ansible.raw_arguments = ['--timeout=300']

请参见此处:https://github.com/mitchellh/vagrant/issues/4860

关于vagrant - Ansible 在第一次运行时总是失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25974783/

相关文章:

vagrant - 命令 'vagrant box add' 失败

composer-php - 如何修复 "https://repo.packagist.org/packages.json does not contain valid Json"?

ios - Apache 在 Vagrant 中创建/编写目录

macos - 将本地编辑器与 Vagrant 一起使用

symfony - 绕过 HSTS 错误给出 'file not found'

ssh - Ansible 如何在 ansible 2.7.x 之前忽略无法访问的主机

ansible - 使用 ansible 在远程主机上启动长时间运行的进程

带有ansible等待数据库的docker

Ansible/神社 : how to convert number to binary format

ios - ansible - 思科 IOS 和 "reload"命令