I'm still new to vagrant and I'm trying to pull up a jenkins, svn instance and a couple of clients and that's all fine but I'm then trying to push the jenkins root ssh key out so it can connect to the other boxes pretty much straight away, and that's where I'm failing.
I'm trying to set a variable depending on the output of a cat inside the box and it doesn't work, the other boxes just get a blank authorized_keys. I'm sure there's a way to do this but I can't see it. I tried putting a "puts" at the end to print the variable but vagrant doesn't seem to run a puts like standard ruby would.
Here's my vagrantfile. I've bolded the non-working bits. Thanks in advance.
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
SUBNET="10.0.10"
#
vmcount=1
Vagrant.configure(2) do |config|
jenkins = "#{SUBNET}.100"
subversion = "#{SUBNET}.150"
# Jenkins box
$jenkinsInstall= <<SCRIPT
sudo apt-get update -y
sudo apt-get install jenkins -y
sudo ssh-keygen -b 2048 -t rsa -f /root/.ssh/id_rsa -q -N ""
systemctl stop jenkins
systemctl start jenkins
SCRIPT
config.vm.define "jenkins_server" do |j|
j.vm.provider "virtualbox" do |v|
end
j.vm.box = "mokote/debian-8"
j.vm.network "private_network", ip: "#{jenkins}"
j.vm.network :forwarded_port, guest: 8080, host: 8082
j.vm.hostname = "jenkins.keef.local"
j.vm.provision "shell", inline: $jenkinsInstall
$ssh_pub_key = j.vm.provision "shell", inline: "sudo cat /root/.ssh/id_rsa.pub"
end
# subversion box
$subversionInstall= <<SCRIPT
sudo apt-get install subversion -y
sudo mkdir /svn-repo
sudo chmod 777 /svn-repo
sudo svnadmin create /svn-repo
sudo svnserve -d
sudo mkdir /root/.ssh/
SCRIPT
config.vm.define "subversion_server" do |s|
s.vm.provider "virtualbox" do |v|
end
s.vm.box = "mokote/debian-8"
s.vm.network "private_network", ip: "#{subversion}"
s.vm.network :forwarded_port, guest: 3690, host: 3690
s.vm.hostname = "subversion.keef.local"
s.vm.provision "shell", inline: $subversionInstall
s.vm.provision "shell", inline: "sudo echo #{$ssh_pub_key} >> /root/.ssh/authorized_keys"
end
# generic clients
$clientInstall= <<SCRIPT
sudo yum install -y subversion ruby
sudo mkdir /root/.ssh/
SCRIPT
(1..vmcount.to_i).each do |host|
hosts = "node#{host}.keef.local"
config.vm.define hosts do |cl|
cl.vm.provider "virtualbox" do |v|
end
cl.vm.box = "chef/centos-7.0"
cl.vm.hostname = hosts
cl.vm.network "private_network", ip: "#{SUBNET}.#{host + 10}"
cl.vm.provision "shell", inline: $clientInstall
cl.vm.provision "shell", inline: "sudo echo #{$ssh_pub_key} >> /root/.ssh/authorized_keys"
end
end
end