在Fedora Linux 3.6.11系统上,我正在使用Jenkins同时运行两个使用相同脚本的作业来测试两个不同VM上的软件包。其中一个作业通常会失败,因为Vagrant不能ssh(1)到它刚刚创建的VM。
该脚本包含:
set -e
$vmName=...
( flock 9; vagrant up $vmName # attempt to prevent concurrent "vagrant up"
) 9>/tmp/`basename $0`-$USER
trap "vagrant destroy --force $vmName; `trap -p EXIT`" EXIT
# Execute test commands on the virtual machine:
vagrant ssh $vmName -- -T <<EOF
...
EOF
这是失败输出(有一些省略):
+ flock 9
+ vagrant up centos64_64
Bringing machine 'centos64_64' up with 'virtualbox' provider...
==> centos64_64: Importing base box 'centos-6.4-x86_64-devel'...
[KProgress: 10%
...
[K==> centos64_64: Matching MAC address for NAT networking...
==> centos64_64: Setting the name of the VM: delivery_centos64_64_1425494409930_40170
==> centos64_64: Fixed port collision for 22 => 2222. Now on port 2200.
==> centos64_64: Clearing any previously set network interfaces...
==> centos64_64: Preparing network interfaces based on configuration...
centos64_64: Adapter 1: nat
==> centos64_64: Forwarding ports...
centos64_64: 22 => 2200 (adapter 1)
==> centos64_64: Booting VM...
==> centos64_64: Waiting for machine to boot. This may take a few minutes...
centos64_64: SSH address: 127.0.0.1:2200
centos64_64: SSH username: vagrant
centos64_64: SSH auth method: private key
centos64_64: Warning: Connection timeout. Retrying...
centos64_64: Warning: Connection timeout. Retrying...
centos64_64: Warning: Remote connection disconnect. Retrying...
==> centos64_64: Machine booted and ready!
==> centos64_64: Checking for guest additions in VM...
==> centos64_64: Mounting shared folders...
centos64_64: /vagrant = <http://spock:8080/jenkins/job/LDM_Acceptance_64 bit_CentOS_6.4/ws/archive/delivery>
centos64_64: /tmp/vagrant-puppet-2/manifests => <http://spock:8080/jenkins/job/LDM_Acceptance_64-bit_CentOS_6.4/ws/archive/delivery/puppet>
==> centos64_64: Running provisioner: puppet...
==> centos64_64: Running Puppet with centos-devel.pp...
==> centos64_64: Notice: Compiled catalog for centos6464.unidata.ucar.edu in environment production in 1.30 seconds
++ trap -p EXIT
+ trap 'vagrant destroy --force centos64_64; ' EXIT
+ vagrant ssh centos64_64 -- -T
VM must be running to open SSH connection. Run `vagrant up`
to start the virtual machine.
+ vagrant destroy --force centos64_64
==> centos64_64: Destroying VM and associated drives...
==> centos64_64: Running cleanup tasks for 'puppet' provisioner...
两个虚拟机都是NAT。成功作业的VM获得ssh(1)的端口2222,而失败作业的VM(上面)获得端口2200.每个作业都有自己的目录和Vagrantfile的副本。
关于如何确保vagrant ssh
- 成功的任何建议都将受到赞赏。