title: Chef deploy_resource private repo, ssh deploy keys and ssh_wrapper
body: <p>I'm having loads of trouble getting my Chef recipe to clone a private repo. Well, I had it working yesterday but after 'cheffin' my Vagrant box half a dozen times, I've broken it. I'm a Chef newbie as you may guess.</p>
  
  <p>Following the deploy_resource guide here, I've created my deploy.rb recipe (shortened):</p>
  
  <pre><code>deploy_branch "/var/www/html/ps" do
    repo              git@github.com:simonmorley/private-v2.git
    ssh_wrapper       "/tmp/.ssh/chef_ssh_deploy_wrapper.sh"
    branch            "rails4"
    migrate           false
    environment       "RAILS_ENV" =&gt; node[:ps][:rails_env] 
    purge_before_symlink %w{conf data log tmp public/system public/assets}
    create_dirs_before_symlink []
    symlinks(                        # the arrow is sort of reversed:
      "conf"   =&gt; "conf",            # current/conf          -&gt; shared/conf
      "data"   =&gt; "data",            # current/data          -&gt; shared/data
      "log"    =&gt; "log",             # current/log           -&gt; shared/log
      "tmp"    =&gt; "tmp",             # current/tmp           -&gt; shared/tmp
      "system" =&gt; "public/system",   # current/public/system -&gt; shared/system
      "assets" =&gt; "public/assets"    # current/public/assets -&gt; shared/assets
    )
    scm_provider Chef::Provider::Git # is the default, for svn: Chef::Provider::Subversion
    notifies :restart, "service[ps]"
    notifies :restart, "service[nginx]"
  end
  </code></pre>
  
  <p>In defaults, I have the following to create the dirs etc.</p>
  
  <pre><code>directory "/tmp/.ssh" do
    action :create
    owner node[:base][:username]
    group node[:base][:username]
    recursive true
  end
  
  template "/tmp/.ssh/chef_ssh_deploy_wrapper.sh" do
    source "chef_ssh_deploy_wrapper.sh.erb"
    owner node[:base][:username]
    mode 0770
  end
  
  # Put SSH private key to be used with SSH wrapper
  template "/tmp/.ssh/id_deploy" do
    source "id_rsa.pub.erb"
    owner node[:base][:username]
    mode 0600
  end
  </code></pre>
  
  <p>And in the wrapper:</p>
  
  <pre><code>#!/bin/sh
  exec ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "/tmp/.ssh/id_deploy" "$@"
  </code></pre>
  
  <p>And I have created a public key and uploaded this to github. </p>
  
  <p>When I deploy the recipe, it gives me an error:</p>
  
  <pre><code> deploy_branch[/var/www/html/ps] action deployEnter passphrase for key '/tmp/.ssh/id_deploy': 
  </code></pre>
  
  <p>Obvs I don't have a password set... The private key must therefore be missing..</p>
  
  <p>Just by chance, I removed the id_deploy key from the recipe, deleted the folders and ran it again. Low and behold, it started working... The reason being that the id_rsa.pub &amp;&amp; id_rsa files were in /root/.ssh from when I manually generated them to test.</p>
  
  <p>I don't understand what I'm doing wrong here. My questions are therefore:</p>
  
  <ul>
  <li>Do I need a private and public key on each node I deploy to? The docs don't mention this.</li>
  <li>Should this not be deploying as non-root user? I have set a user in my roles file..</li>
  <li>Why is the ssh_wrapper not doing what it's supposed to</li>
  </ul>