From 3baeaadd0dae797fb110fe6ffd2cd6ff3be419cb Mon Sep 17 00:00:00 2001 From: Brian Dols Date: Mon, 8 Oct 2012 00:42:55 -0500 Subject: [PATCH] automate setup portion of granting jenkins access to a github repo --- attributes/default.rb | 5 +++-- files/default/github_keys.pub | 2 ++ recipes/default.rb | 29 +++++++++++++++++++++++++++++ templates/default/dot_gitconfig.erb | 3 +++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 files/default/github_keys.pub create mode 100644 templates/default/dot_gitconfig.erb diff --git a/attributes/default.rb b/attributes/default.rb index 42caf88..b740caf 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -8,8 +8,7 @@ # # Copyright 2010, VMware, Inc. # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. +# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 @@ -24,6 +23,8 @@ default[:jenkins][:mirror] = "http://mirrors.jenkins-ci.org" default[:jenkins][:package_url] = "http://pkg.jenkins-ci.org" default[:jenkins][:java_home] = ENV['JAVA_HOME'] +default[:jenkins][:build_user_email] = "jenkins-build@#{node[:fdqn]}" +default[:jenkins][:build_user_name] = "automated build process" default[:jenkins][:server][:home] = "/var/lib/jenkins" default[:jenkins][:server][:user] = "jenkins" diff --git a/files/default/github_keys.pub b/files/default/github_keys.pub new file mode 100644 index 0000000..2dc78fc --- /dev/null +++ b/files/default/github_keys.pub @@ -0,0 +1,2 @@ +|1|PqPXrISFgHy5RWIfbyYGR7KIL28=|RfHGHY2BbmNjcxg5WSNaXx3bWzo= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== +|1|d7o19/ibbnCCocPRkaivkSBaN30=|ytVikmR/5WzQ4uwLqF0yQc7sbok= ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ== diff --git a/recipes/default.rb b/recipes/default.rb index 7c359e2..1160bed 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -41,6 +41,28 @@ group node[:jenkins][:server][:group] end +#cookbook_file "#{pkey}" do + #source "id_rsa" + #mode 0600 + #owner node[:jenkins][:server][:user] + #group node[:jenkins][:server][:group] +#end + +#cookbook_file "#{pkey}.pub" do + #source "id_rsa.pub" + #mode 0644 + #owner node[:jenkins][:server][:user] + #group node[:jenkins][:server][:group] +#end + +cookbook_file "#{node[:jenkins][:server][:home]}/.ssh/known_hosts" do + source "github_keys.pub" + mode 0644 + owner node[:jenkins][:server][:user] + group node[:jenkins][:server][:group] +end + + execute "ssh-keygen -f #{pkey} -N ''" do user node[:jenkins][:server][:user] group node[:jenkins][:server][:group] @@ -53,6 +75,13 @@ end end +template "#{node[:jenkins][:server][:home]}/.gitconfig" do + source "dot_gitconfig.erb" + mode 0664 + owner node[:jenkins][:server][:user] + group node[:jenkins][:server][:group] +end + directory "#{node[:jenkins][:server][:home]}/plugins" do owner node[:jenkins][:server][:user] group node[:jenkins][:server][:group] diff --git a/templates/default/dot_gitconfig.erb b/templates/default/dot_gitconfig.erb new file mode 100644 index 0000000..7e5fc2e --- /dev/null +++ b/templates/default/dot_gitconfig.erb @@ -0,0 +1,3 @@ +[user] + email = <%= node[:jenkins][:build_user_email] %> + name = <%= node[:jenkins][:build_user_name] %>