So I'm setting up a vagrant environment for our small team of 4 developers. I'm using an Ubuntu/Precise32 box and I created a shell script for provisioning with lots of apt-get and cp calls. Something like this:
#!/bin/bash
#filename: provision.sh
sudo apt-get update
apt-get install debconf-utils -y > /dev/null
debconf-set-selections <<< "mysql-server mysql-server/root_password password myPassword"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password myPassword"
sudo apt-get install -y vim apache2 mysql-server-5.5 mysql-client git sqlite python-pip phpmyadmin
sudo pip install virtualenv
sudo pip install Django==1.4
sudo a2enmod rewrite
sudo service apache2 restart
echo "Copying hosts ..."
sudo cp /vagrant/hosts /etc/
echo "Copying .gitconfig ..."
sudo cp /vagrant/.gitconfig /home/vagrant/
echo "Copying .bashrc ..."
sudo cp /vagrant/.bashrc /home/vagrant/
echo "Copying .bash_aliases ..."
sudo cp /vagrant/.bash_aliases /home/vagrant/
sudo ln -fs /usr/share/phpmyadmin /var/www
if [ ! -d "/vagrant/projects" ]; then
echo "Creating folder /vagrant/projects"
mkdir /vagrant/projects
fi
cd /vagrant/projects
#git clone myServer:/git/project.git
#can't clone because the user is vagrant. tries ssh vagrant@myServer asking for a password
Now I would like to clone some git repositories (from our own servers) if they don't already exist. But within the provision the active user is vagrant and I don't want to create a vagrant user on our git server or any other servers that we could use.
Each developer in the team already have their ssh accounts on other servers. So should I just create all the users in all the vagrant boxes? And if so, how can they ssh into other servers with no password?
I don't want the developers (myself included) to make user management on their own vagrant box (stuff like adduser, ssh-copy-id etc...). I want to provision everything like cloning git repositories and maybe rsync'ing but I want to be able to set up the right user for different vagrant boxes.
I want to be able to do this from shell provision:
If Vagrant box 1 => create user developer1 that already has passwordless ssh access to our servers
If Vagrant box 2 => create user developer2 that already has passwordless ssh access to our servers
If Vagrant box 3 => create user developer3 that already has passwordless ssh access to our servers
If Vagrant box 4 => create user developer4 that already has passwordless ssh access to our servers
Thank you!
I don't know the answer, but hopefully I may be able to point you in the direction of a possible solution.
I'm guessing the /vagrant share will point to the host in your setup, in which case you could store that information in the project folder on the individual developer's machines and then call / use it in the provisioning setup.
Alternatively, try using 'Socket.gethostname' in the vagrant file - in Ruby it returns the host computer's name, so you could use this to sniff which on which developer's machine the vagrant file is running.
i.e.
if Socket.gethostname === 'Developer1PC'
end
if Socket.gethostname === 'Developer2PC'
end
if Socket.gethostname === 'Developer3PC'
end
if Socket.gethostname === 'Developer4PC'
end
You'll have to excuse any ruby errors, I'm not a ruby dev, but I've just had to do something along similar lines in Vagrant.