title: SSH into a Vagrant machine with Ansible
body: <p>Normally, you can ssh into a Vagrant-managed VM with <code>vagrant ssh</code>. There are two options:</p>
  
  <ol>
  <li>You can use an <code>insecure_private_key</code> generated by Vagrant to
  authenticate.  </li>
  <li>Use your own private key - provided that
  <code>config.ssh.forward_agent</code> is set to <code>true</code>, and the VM is
  configured correctly</li>
  </ol>
  
  <p>I use the second option. S when I run <code>vagrant ssh</code>, I ssh into the machine with my custom private key.</p>
  
  <p>Now I need to let Ansible SSH into my Vagrant machine and I do not want to use <code>Vagrantfile</code> for it.</p>
  
  <p>So I executed:</p>
  
  <p><code>ansible-playbook -i hosts/development --private-key=~/.ssh/id_rsa -u vagrant dev.yml</code></p>
  
  <p>And I have this error returned:</p>
  
  <blockquote>
    <p>fatal: [192.168.50.5] => SSH Error: Permission denied (publickey).
    while connecting to 192.168.50.5:22</p>
  </blockquote>
  
  <p>The <code>hosts/inventory</code> file holds just the IP of my Vagrant VM (192.168.50.5).</p>
  
  <p>I do not know why Ansible cannot ssh into the VM. It's using exactly the same user (<code>vagrant</code>) and key (<code>id_rsa</code>) as when executing <code>vagrant ssh</code>.</p>
  
  <p>However, there is no problem sshing with <code>vagrant ssh</code> while the above would not run.</p>
  
  <p>Any suggestions would be much appreciated.</p>