0

I have a last version Jenkis (run under the Tomcat) and the Vagrant and LXC container. Tomcat running under jenkins user. I have next Vagrantfile

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

So, when I ran lxc container from bash by vagrant up everything was fine. And vagrant ssh worked. But if I run it via Jenkins job I get this

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 job contains only these commands

!#/bin/bash
cd vagrant
vagrant up

In process of investigation I found next different. Then I ran from bash the vagrant ssh-config out this:

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

But then I ran from Jenkins job I got this

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

What did I do wrong?

Stanislav Bashkyrtsev
  • 14,470
  • 7
  • 42
  • 45
Stan Dudikoff
  • 94
  • 1
  • 8

1 Answers1

0

EDIT:

arjenvrielink/xenial64-lxc is an official box So I'm still pretty sure your problem is with the vagrant insecure key replacement mecanism but my solution won't help you.


Is arjenvrielink/xenial64-lxc a custom box ?

If so make sure to either let the insecure key in it so any new user(Jenkins included) will have access to the box because at fist up vagrant connect to the box using the insecure key then create a new one.

If you want to include your own key in the box make sure to add the following lines to your Vagrantfile:

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

The caveat is you'll have to make the key available everywhere you vagrant environement will run.

lee-pai-long
  • 2,147
  • 17
  • 18
  • Sorry, but not. I setuped the DEP version of Jenkins like temp solution. There isn't any problem like one. But I found out an one thing. Then I used Tomcat version the tmp folder is inside Tomcat home folder. Then I used DEP package the tmp folder is inside root. Maybe this is a key to solution. I'll be check later. – Stan Dudikoff Jun 22 '17 at 10:28
  • Sorry but I don't understand. What do you mean by "I setuped the DEP version of Jenkins like temp solution" ? The sentences "There isn't any problem like one. But I found out an one thing." Don't make sense what are you trying to say exactly ? Anyhow the error you have "default: Warning: Authentication failure. Retrying..." came from a problem with vagrant SSH key, nothing to do with tomcat or even really jenkins IMHO. – lee-pai-long Jun 22 '17 at 12:46
  • Also your script do a "cd vagrant" but relative to where exactly ? – lee-pai-long Jun 22 '17 at 12:57
  • I have only one user account and it is Jenkins. This account I use for all my tasks. So even Tomcat is running under this account. And I try to run same tasks. I wanna run lxc container by vagrant up. But when I run this command like Jenkins job under Tomcat I got "default: Warning: Authentication failure. Retrying..." If I run it under just bash under same account I've not this error. Do you understen d? All tasks I make with same permissons. And same folder.And if I use Jenkins like java application (dep package for Ubuntu) I don't have same problem too. Ok? – Stan Dudikoff Jun 22 '17 at 13:07
  • So the root of problem are Tomcat settings I think. – Stan Dudikoff Jun 22 '17 at 13:10
  • Ok I understand. – lee-pai-long Jun 22 '17 at 13:15
  • Unfortunately changed the path TMP dir of Tomcat didn't fix this problem. I don't know what I can to do more... I have not any idea – Stan Dudikoff Jun 22 '17 at 14:00
  • Dit you use [jenkins vagrant plugin](https://github.com/jenkinsci/vagrant-plugin) or just a bare script ? – lee-pai-long Jun 22 '17 at 14:58
  • just script. I have difficult configuration and apply Ansible. So this plug-in is not fit for me. It is too simple. But I can't just run this container. – Stan Dudikoff Jun 22 '17 at 15:29