Skip to content

Instantly share code, notes, and snippets.

@lancelakey
Created July 9, 2013 01:28
Show Gist options
  • Save lancelakey/5953926 to your computer and use it in GitHub Desktop.
Save lancelakey/5953926 to your computer and use it in GitHub Desktop.
Vagrant and ssh-agent forwarding

Vagrant and ssh-agent forwarding

I wanted some of my Vagrant instances to be able to git clone private repositories without having to store any ssh keys in any cookbooks, repositories, etc.

This is a dirty hack but it works better than anything else I've found so far.

Vagrant.configure("2") do |config|
  config.vm.hostname = "example"
  config.vm.box = "debian"
  config.vm.box_url = "example.com"
  config.omnibus.chef_version = :latest
  config.vm.network :private_network, ip: "33.33.33.10"
  config.ssh.max_tries = 40
  config.ssh.timeout = 120

  # Configure ssh-agent forwrading
  # This allows the virtual machine to use your local ssh-agent identities
  config.ssh.forward_agent = true

  config.vm.provision :shell do |shell|
    shell.inline = "touch $1 && chmod 0440 $1 && echo $2 > $1"
    shell.args = %q{/etc/sudoers.d/root_ssh_agent "Defaults env_keep += \"SSH_AUTH_SOCK\""}
  end

  # Add github.com to known_hosts
  config.vm.provision :shell do |shell|
    shell.inline = "sudo ssh -qT -o StrictHostKeyChecking=no [email protected] || :"
  end

  # Configure chef-solo and berkshelf
  config.berkshelf.enabled = true
  config.vm.provision :chef_solo do |chef|
    chef.log_level = "debug"
    chef.json = {
      :mysql => {
        :server_root_password => 'rootpass',
        :server_debian_password => 'debpass',
        :server_repl_password => 'replpass'
      }
    }
    chef.run_list = [
      "recipe[example::default]"
    ]
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment