diff --git a/lib/puppet-standalone-mashup/capistrano.rb b/lib/puppet-standalone-mashup/capistrano.rb index 9ecc7d5..f8a492a 100644 --- a/lib/puppet-standalone-mashup/capistrano.rb +++ b/lib/puppet-standalone-mashup/capistrano.rb @@ -166,5 +166,20 @@ Capistrano::Configuration.instance.load do def with_additional_puppet_bin_path additional_puppet_bin_path ? %{PATH="#{additional_puppet_bin_path}:$PATH"} : '' 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 diff --git a/shared/lib/puppet/provider/git/clone.rb b/shared/lib/puppet/provider/git/clone.rb index 246389e..c45550c 100644 --- a/shared/lib/puppet/provider/git/clone.rb +++ b/shared/lib/puppet/provider/git/clone.rb @@ -2,6 +2,14 @@ Puppet::Type.type(:git).provide(:clone) do desc "Clone/pull a git repo" def create + p ENV + + system key_check_command + + if $?.exitstatus != 0 + system keyscan_command + end + if File.directory?(path) Dir.chdir(path) { system git_command("pull origin master") } else @@ -19,9 +27,25 @@ Puppet::Type.type(:git).provide(:clone) do private 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 def path diff --git a/shared/lib/puppet/type/git.rb b/shared/lib/puppet/type/git.rb index ff23134..8b8856b 100644 --- a/shared/lib/puppet/type/git.rb +++ b/shared/lib/puppet/type/git.rb @@ -22,5 +22,9 @@ Puppet::Type.newtype(:git) do newparam(:user) do desc "The user to perform the command as" end + + newparam(:host) do + desc "The host to connect to" + end end diff --git a/shared/modules/mkdir_p/manifests/init.pp b/shared/modules/mkdir_p/manifests/init.pp index d1d40c0..d6393b9 100644 --- a/shared/modules/mkdir_p/manifests/init.pp +++ b/shared/modules/mkdir_p/manifests/init.pp @@ -1,7 +1,14 @@ -define mkdir_p($path) { +define mkdir_p($path, $owner = '') { exec { "mkdir -p ${name}": path => $path, unless => "test -d ${name}" } + + if ($owner != '') { + exec { "chown ${owner} ${name}": + path => $path, + require => Exec["mkdir -p ${name}"] + } + } }