Git authentication in Chef

Viewed 12395

When deploying an application with Chef, I've got the code base set to be cloned from a private github repository with the following resource:

git '/mnt/application' do
    repository 'git@github.com:organization/repository'

    reference 'master'
    action :sync

    user node.application.user
    group node.application.user
end

However, after scanning the documentation for the git resource, I can't see how you supply the key file for authentication. I'm also confused as to how to store this key in a data bag, as the file contains a bunch of new lines. Any ideas?

6 Answers

Based on the hint by sadaf2605, this was the easiest way for me – I just had to make sure to set the correct user/group as well as turn off StrictHostKeyChecking:

git '/path/to/destination' do
  environment 'GIT_SSH_COMMAND' => 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /path/to/private_key'
  repository 'git@github.com:your/repo.git'
  reference 'master'
  action :sync
  user 'vagrant'
  group 'vagrant'
end

You should try this cookbook https://github.com/poise/application_git. It solves the problem that you mentioned.

With this cookbook, you can use application_git resource, specifiyng the private key:

application_git '/srv/myapp' do
  repository 'git@github.com:organization/repository'
  deploy_key '/some/path/id_rsa'
end
Related