Skip to content

Instantly share code, notes, and snippets.

@Atalanta
Created January 28, 2011 11:34
Show Gist options
  • Save Atalanta/800142 to your computer and use it in GitHub Desktop.
Save Atalanta/800142 to your computer and use it in GitHub Desktop.
users = search(:users, "repos:*")
shared_repos = search(:git_repos, "url:*")
users.each do |u|
username = u['id']
if u.has_key?("git_key")
template("/home/#{username}/.ssh/config") do
source "git-ssh-config.erb"
owner username
group username
mode "0600"
variables u.to_hash
end
end
if u.has_key?("repos")
u["repos"].each do |target, repo|
git "/home/#{username}/#{target}" do
repository repo['repo']
reference repo['revision']
action :checkout
user username
end
end
end
shared_repos.each do |shared_repo|
git "/home/#{username}/#{shared_repo['id']}" do
repository shared_repo["url"]
reference shared_repo["revision"]
action :checkout
user username
only_if {File.exists?("/home/#{username}/.ssh/#{u['git_key']['name']}")}
end
end
end
{ "id": "bert",
"git_key": {
"name": "git-key-rsa",
"public":"ssh-rsa ABCDEFG"
},
% knife data bag show git_repos test_lab
{
"url": "git@git.dtotc.me:test_lab.git",
"id": "test_lab",
"revision": "HEAD"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment