title: Ansible bitbucket clone provisioning ssh error
body: <p>In summary, When provisioning my vagrant box using Ansible, I get thrown a mysterious error when trying to clone my bitbucket private repo using ssh.
  The error states that the &quot;Host key verification failed&quot;.</p>
  <p>Yet if I vagrant ssh and then run the '<em>git clone</em>' command, the private repo is successfully cloned. This indicates that the ssh forward agent is indeed working and the vagrant box can access my private key associated with the bitbucket repo.</p>
  <p>I have been struggling for two days on this issue and am loosing my mind!
  Please, somebody help me!!!</p>
  <p><strong>Vagrantfile:</strong></p>
  <pre><code>Vagrant.configure(&quot;2&quot;) do |config|
    config.vm.box = &quot;ubuntu/xenial64&quot;
    config.vm.network &quot;private_network&quot;, ip: &quot;192.168.33.10&quot;
    config.ssh.forward_agent = true
      
    # Only contains ansible dependencies
    config.vm.provision &quot;shell&quot;,
      inline: &quot;sudo apt-get install python-minimal -y&quot;
  
    # Use ansible for all provisioning:
    config.vm.provision &quot;ansible&quot; do |ansible|
      ansible.playbook = &quot;provisioning/playbook.yml&quot;
    end
  
  end
  </code></pre>
  <p>My <strong>playbook.yml</strong> is as follows:</p>
  <pre><code>---
  
  - hosts: all
    become: true
  
    tasks:
      - name: create /var/www/ directory
        file: dest=/var/www/ state=directory owner=www-data group=www-data mode=0755
  
      - name: Add the user 'ubuntu' to group 'www-data'
        user:
          name: ubuntu
          shell: /bin/bash
          groups: www-data
          append: yes
        
      - name: Clone bitbucket repo
        git:
          repo: git@bitbucket.org:gustavmahler/example.com.git
          dest: /var/www/poo
          version: master
          accept_hostkey: yes
  </code></pre>
  <p><strong>Error Message:</strong></p>
  <p><code>vagrant provision</code></p>
  <blockquote>
  <p>TASK [common : Clone bitbucket repo] *******************************************</p>
  <p>fatal: [default]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;cmd&quot;: &quot;/usr/bin/git clone --origin origin '' /var/www/poo&quot;, &quot;failed&quot;: true, &quot;msg&quot;: &quot;Cloning into '/var/www/poo'...\nWarning: Permanently added the RSA host key for IP address '104.192.143.3' to the list of known hosts.\r\nPermission denied (publickey).\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.&quot;, &quot;rc&quot;: 128, &quot;stderr&quot;: &quot;Cloning into '/var/www/poo'...\nWarning: Permanently added the RSA host key for IP address '104.192.143.3' to the list of known hosts.\r\nPermission denied (publickey).\r\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.\n&quot;, &quot;stderr_lines&quot;: [&quot;Cloning into '/var/www/poo'...&quot;, &quot;Warning: Permanently added the RSA host key for IP address '104.192.143.3' to the list of known hosts.&quot;, &quot;Permission denied (publickey).&quot;, &quot;fatal: Could not read from remote repository.&quot;, &quot;&quot;, &quot;Please make sure you have the correct access rights&quot;, &quot;and the repository exists.&quot;], &quot;stdout&quot;: &quot;&quot;, &quot;stdout_lines&quot;: []}</p>
  </blockquote>
  <p><strong>Additional Info:</strong></p>
  <ul>
  <li><em>ssh-add -l</em> on my machine does contain the associated bitbucket repo key.</li>
  <li><em>ssh-add -l</em> inside the vagrant box does also contain the associated bitbucket repo key (through ssh-forwarding).</li>
  </ul>
  <p><strong>Yet cloning works</strong> if done manually inside the vagrant box <strong>?</strong>:</p>
  <pre><code>vagrant ssh
  git clone git@bitbucket.org:myusername/myprivaterepo.com.git
  Then type &quot;yes&quot; to allow the RSA fingerprint to be added to ~/.ssh/known_hosts (as its first connection with bitbucket)
  </code></pre>
  <p><strong>Possible solution?</strong></p>
  <p>I have seen in the Ansible documentation that there is a <em><a href="http://docs.ansible.com/ansible/latest/git_module.html#options" rel="nofollow noreferrer">key_file</a>:</em> option. How would I reference the private key which is located outside the vagrant box and is passed in using ssh forwarding?</p>
  <p>I do have multiple ssh keys for different entities inside my ~/.ssh/ Perhaps the git clone command when run by Ansible provisioning isn't selecting the correct key?</p>
  <p>Any help is greatly appreciated and thanks for reading my nightmare.</p>