Jenkins和Vagrant有很奇怪的情况

时间:2017-06-21 13:19:36

标签: linux jenkins ssh vagrant lxc

我有最后一个版本Jenkis(在Tomcat下运行)和Vagrant和LXC容器。 Tomcat在jenkins用户下运行。我有下一个Vagrantfile

Vagrant.configure(2) do |config|
  config.vm.box = "arjenvrielink/xenial64-lxc"
  config.vm.provider :lxc do |lxc|
    lxc.backingstore = 'dir'
  end
end

所以,当我通过vagrant up从bash运行lxc容器时一切都很好。 vagrant ssh工作了。但如果我通过詹金斯的工作来运行它,我会得到这个

Started by user admin
[EnvInject] - Loading node environment variables.
Building in workspace /home/jenkins/workspaces/server
[server] $ /bin/bash /opt/tomcat/temp/jenkins204809790857124992.sh
Bringing machine 'default' up with 'lxc' provider...
==> default: Importing base box 'arjenvrielink/xenial64-lxc'...
==> default: Checking if box 'arjenvrielink/xenial64-lxc' is up to date...
==> default: Setting up mount entries for shared folders...
    default: /vagrant => /home/jenkins/workspaces/server/vagrant
==> default: Starting container...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 10.0.3.29:22
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Authentication failure. Retrying...
    default: Warning: Authentication failure. Retrying...
Build was aborted
Aborted by admin
Finished: ABORTED

Jenkins作业只包含这些命令

!#/bin/bash
cd vagrant
vagrant up

在调查过程中,我发现接下来有所不同。然后我从bash vagrant ssh-config跑出来:

Host default
  HostName 10.0.3.212
  User vagrant
  Port 22
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/jenkins/workspaces/server/vagrant/.vagrant/machines/default/lxc/private_key
  IdentitiesOnly yes
  LogLevel FATAL

然后我从詹金斯的工作中跑出了我的这个

Host default
  HostName 10.0.3.217
  User vagrant
  Port 22
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /home/jenkins/.vagrant.d/insecure_private_key
  IdentitiesOnly yes
  LogLevel FATAL

我做错了什么?

1 个答案:

答案 0 :(得分:0)

编辑:

arjenvrielink/xenial64-lxcan official box 因此,我仍然非常确定您的问题与流浪者insecure key replacement mecanism有关,但我的解决方案对您没有帮助。

arjenvrielink/xenial64-lxc是自定义框吗?

如果是这样,请确保让不安全的密钥进入,以便任何新用户(包括Jenkins)都可以访问该框,因为在使用不安全密钥的拳头向上流浪者连接到框时,然后创建一个新的。

如果您想在框中包含您自己的密钥,请确保将以下行添加到您的Vagrant文​​件中:

Vagrant.configure("2") do |config|
  config.ssh.private_key_path = File.expand_path("<path of the key relative to Vagrantfile>", __FILE__)
end

需要注意的是,您必须在流浪环境运行的任何地方都可以使用密钥。