I’m trying to use vagrant to set up a dev environment that automatically clones two repositories if they haven’t already been cloned.
I wrote a simple script to clone the repos, after failing in many, many ways to get puppet to run the git command directly. For some reason I thought this method would be foolproof, but it turns out I’m a better fool than I thought.
exec {"load-repos":
command =>"/bin/bash /vagrant/manifests/modules/scripts/clone_repos.sh",
require => Package["git-core"],
}
Here’s the script:
#!/bin/bash
if [ ! -d /vagrant/repo-one-dest ]; then
git clone git@example.com:/repo-one.git /vagrant/repo-one-dest
fi
if [ ! -d /vagrant/repo-two-dest ]; then
git clone git@example.com:/repo-two.git /vagrant/repo-two-dest
fi
exit
The private keys are set up properly. When I log into the vm and manually run bash clone_repos.sh, everything works. No matter how many times I reload vagrant and let puppet do its thing, the repos are never loaded via the exec. What am I missing?
This is probably because when you
vagrant sshyou’re usually logging in as thevagrantuser (by default, though this can certainly be modified via configuration). Thevagrantuser I’m guessing has the keys setup properly.When Vagrant runs your provisioner (Puppet, in this case), however, it does a
sudo, so it runs as the root user.The way I generally recommend setting up keys to do the deploy is to put the keys somewhere, and then use a
GIT_SSHwrapper to properly clone it, or to use SSH agents.