some work on making things better

This commit is contained in:
John Bintz 2012-08-14 21:35:41 -04:00
parent 885c685e1a
commit ff3fffc206
4 changed files with 53 additions and 3 deletions

View File

@ -166,5 +166,20 @@ Capistrano::Configuration.instance.load do
def with_additional_puppet_bin_path def with_additional_puppet_bin_path
additional_puppet_bin_path ? %{PATH="#{additional_puppet_bin_path}:$PATH"} : '' additional_puppet_bin_path ? %{PATH="#{additional_puppet_bin_path}:$PATH"} : ''
end end
desc "Get managing user's public key"
task :public_key do
as_user = ->(command) { %{sudo -u #{user} -- #{command}} }
key = capture(as_user.("cat ~/.ssh/id_dsa.pub 2>/dev/null ; true"))
if key.empty?
if Capistrano::CLI.ui.ask("No key found. Generate a key?")
run as_user.("ssh-keygen -f ~/.ssh/id_dsa -t dsa -N ''")
key = capture(as_user("cat ~/.ssh/id_dsa.pub"))
end
end
$stdout.puts "\n#{key}\n"
end
end end

View File

@ -2,6 +2,14 @@ Puppet::Type.type(:git).provide(:clone) do
desc "Clone/pull a git repo" desc "Clone/pull a git repo"
def create def create
p ENV
system key_check_command
if $?.exitstatus != 0
system keyscan_command
end
if File.directory?(path) if File.directory?(path)
Dir.chdir(path) { system git_command("pull origin master") } Dir.chdir(path) { system git_command("pull origin master") }
else else
@ -19,9 +27,25 @@ Puppet::Type.type(:git).provide(:clone) do
private private
def git_command(what) def git_command(what)
user_switch = @resource[:user] ? "sudo -u #{@resource[:user]} -- " : "" path_wrap("git #{what}")
end
%{bash -c 'PATH=#{@resource[:path]} #{user_switch} git #{what}'} def keyscan_command
path_wrap("ssh-keyscan -t dsa,rsa #{@resource[:host]} >> ~/.ssh/known_hosts")
end
def key_check_command
path_wrap("ssh-keygen -F #{@resource[:host]}")
end
def path_wrap(command)
command = %{PATH=#{@resource[:path]} #{command}}
if @resource[:user]
command = %{su -c "#{command}" #{@resource[:user]}}
end
command.tap { |o| p o }
end end
def path def path

View File

@ -22,5 +22,9 @@ Puppet::Type.newtype(:git) do
newparam(:user) do newparam(:user) do
desc "The user to perform the command as" desc "The user to perform the command as"
end end
newparam(:host) do
desc "The host to connect to"
end
end end

View File

@ -1,7 +1,14 @@
define mkdir_p($path) { define mkdir_p($path, $owner = '') {
exec { "mkdir -p ${name}": exec { "mkdir -p ${name}":
path => $path, path => $path,
unless => "test -d ${name}" unless => "test -d ${name}"
} }
if ($owner != '') {
exec { "chown ${owner} ${name}":
path => $path,
require => Exec["mkdir -p ${name}"]
}
}
} }