ansible in masterless mode git task fails while git clone works on remote server
<p>I am using Ansible to clone a repository on a remote server :</p>

<p>This command works on the remote server: <code>git clone git@github.com:ansible/ansible-examples.git</code></p>

<p>This task, however, fails:</p>

<pre><code>- name: clone git repo
      git: repo=git@github.com:ansible/ansible-examples.git 
           dest=/root/ansible-examples
           clone=yes
</code></pre>

<p>With the following output:</p>

<blockquote>
  <p>FAILED! => {"changed": false, "cmd": "/usr/bin/git ls-remote '' -h refs/heads/HEAD", "failed": true, "msg": "Permission denied
  (publickey).\r\nfatal: Could not read from remote
  repository.\n\nPlease make sure you have the correct access
  rights\nand the repository exists.", "rc": 128, "stderr": "Permission
  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", "stdout": "", "stdout_lines":
  []}</p>
</blockquote>

<p>I have a similar situation (ssh and cloning works with CLI but not the task) with a private git repo that I can clone on the remote server (using ssh forwarding) but fails with the same task.</p>

<p>I also have the following in my <code>ansible.cfg</code>:</p>

<pre><code>[defaults]
transport = ssh

# deprecation_warnings = False # In case it matters get the following [DEPRECATION WARNING]: Instead of sudo/sudo_user, use become/become_user and make sure become_method is 'sudo' (default).

[ssh_connection]
ssh_args = -o ForwardAgent=yes
</code></pre>

<p><em>Note:</em> I am using ansible from my OSX laptop, to an Ubuntu remote. The version is <code>ansible 2.1.0.0</code>.</p>

<p>How do I make this task clone the git repository ?</p>

<p><strong>Edit</strong></p>

<p>Unsure what that means, but the following does not work either (and the same in the console works) :</p>

<pre><code>- name: clone git repo
  shell:  if [[ ! -d /root/ansible-examples ]] ; then echo "CLONING" &amp;&amp; git clone git@github.com:ansible/ansible-examples.git /root/ansible-examples ; else echo "already there" ; fi
  args:
    chdir: /root/
    creates: /root/ansible-examples/
</code></pre>

<p><strong>Another attempt:</strong></p>

<pre><code>shell: git clone git@github.com:ansible/ansible-examples.git /root/ansible-examples
</code></pre>

<blockquote>
  <p>FAILED! => {"changed": true, "cmd": "git clone
  git@github.com:ansible/ansible-examples.git /root/ansible-examples",
  "delta": "0:00:00.693890", "end": "2016-06-08 20:57:47.505574",
  "failed": true, "rc": 128, "start": "2016-06-08 20:57:46.811684",
  "stderr": "Cloning into '/root/ansible-examples'...\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.", "stdout": "", "stdout_lines": [],
  "warnings": ["Consider using git module rather than running git"]}</p>
</blockquote>