8

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?

5
  • Missing space on the first [ test. Commented Jun 23, 2012 at 22:13
  • Thanks for pointing that out. Unfortunatley, that's an artifact I introduced into the post when I replaced the real directory with 'repo-one-dest'. The script functions correctly when run from the commandline and has the space. I edited the post to remove the syntax error. Commented Jun 23, 2012 at 22:16
  • 1
    Adding a 'logoutput=>true," to your Exec block may result in more output that may help with debugging. You may also want to add a file["/vagrant/manifests/modules/scripts/clone_repos.sh"] to the require section. Puppet may be trying to execute the script before puppet's pushed it to your VM. Commented Jun 25, 2012 at 18:36
  • I'll try that when I get home tonight. Fairly 100% positive that it's not an issue with the file not existing on the path, but hey, I've been wrong before. Commented Jun 25, 2012 at 21:27
  • BTW: If someone reading this has the time and inclination to solve this problem with a public git repo and post the solution, that would be helpful. Commented Jun 25, 2012 at 21:53

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Good insight. Not sure if it works, but it seems plausible. I wound up altering my workflow, and at this point I'm fine with how things are and probably won't go back to my original plan. If I get some free time I may eventually see if that's the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.