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 [email protected]:/repo-one.git /vagrant/repo-one-dest
fi
if [ ! -d /vagrant/repo-two-dest ]; then
git clone [email protected]:/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?
Whenever we run any command in a Bash shell, a subshell is created by default, and a new child process is spawned (forked) to execute the command. When using exec, however, the command following exec replaces the current shell. This means no subshell is created and the current process is replaced with this new command.
In Puppet, the combined configuration to be applied to a host is called a catalog, and the process of applying it is called a run. The Puppet client software is called the agent. Puppet calls the definition of the host itself a node. The Puppet server is called the master. exec resources.
The exec has refreshonly => true , which allows Puppet to run the command only when some other resource is changed.
This is probably because when you vagrant ssh
you're usually logging in as the vagrant
user (by default, though this can certainly be modified via configuration). The vagrant
user 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_SSH
wrapper to properly clone it, or to use SSH agents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With