# Git clone failing only via Ansible. Working via cmdline.

**URL:** <https://forum.ansible.com/t/git-clone-failing-only-via-ansible-working-via-cmdline/33227>\
**Category:** Ansible Project\
**Created:** [June 21, 2020, 7:46am UTC](https://forum.ansible.com/t/git-clone-failing-only-via-ansible-working-via-cmdline/33227 "2020-06-21T07:46:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mukuntha\_rajaa](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@Mukuntha\_rajaa](https://forum.ansible.com/u/Mukuntha_rajaa)\
**Post date:** [June 21, 2020, 7:46am UTC](https://forum.ansible.com/t/git-clone-failing-only-via-ansible-working-via-cmdline/33227/1 "2020-06-21T07:46:30Z")

</div>

Hello,

When I git clone from cmdline, I am able to clone successfully. But when I do the same thing via, Ansible, something is going wrong.

```auto
git clone git@gitlab.com:xxxx/yyyy.git
Cloning into 'yyyy'...
remote: Enumerating objects: 223, done.
remote: Counting objects: 100% (223/223), done.
remote: Compressing objects: 100% (164/164), done.
remote: Total 223 (delta 21), reused 175 (delta 6), pack-reused 0
Receiving objects: 100% (223/223), 667.18 KiB | 204.00 KiB/s, done.
Resolving deltas: 100% (21/21), done.

```

Also, following is fine.

```auto
ssh -vT [git@gitlab.com](mailto:git@gitlab.com)
[...]
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
**Welcome to GitLab** , @mukuntharajaa!
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [eow@openssh.com](mailto:eow@openssh.com) reply 0
debug1: channel 0: free: client-session, nchannels 1
Transferred: sent 2776, received 3416 bytes, in 0.9 seconds
Bytes per second: sent 2926.2, received 3600.8
debug1: Exit status 0

```

Only via Ansible, git cloning is failing.

```auto
fatal: [192.168.99.105]: FAILED! => {"changed": false, "cmd": ["/usr/bin/git", "fetch", "--tags", "origin"], "msg": "Failed to download remote objects and refs: Load key \"/home/mrajaa/.ssh/id_rsa.pub\": **invalid format\r\[ngit@gitlab.com](mailto:ngit@gitlab.com): 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"}

```

My git clone task is like this,

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [June 21, 2020, 8:00am UTC](https://forum.ansible.com/t/git-clone-failing-only-via-ansible-working-via-cmdline/33227/2 "2020-06-21T08:00:30Z")

</div>

> Hello,
> 
> When I git clone from cmdline, I am able to clone successfully. But when I do the same thing via, Ansible, something is  
> going wrong.
> 
> \>git clone git@gitlab.com:xxxx/yyyy.git Cloning into 'yyyy'... remote: Enumerating objects: 223, done. remote: Counting  
> objects: 100% (223/223), done. remote: Compressing objects: 100% (164/164), done. remote: Total 223 (delta 21), reused  
> 175 (delta 6), pack-reused 0 Receiving objects: 100% (223/223), 667.18 KiB | 204.00 KiB/s, done. Resolving deltas: 100%  
> (21/21), done. |
> 
> Also, following is fine.
> 
> \>ssh -vT git@gitlab.com \<mailto:git@gitlab.com\> [...] debug1: Sending environment. debug1: Sending env LANG =  
> en\_US.UTF-8 \*Welcome to GitLab\*, @mukuntharajaa! debug1: client\_input\_channel\_req: channel 0 rtype exit-status reply 0  
> debug1: client\_input\_channel\_req: channel 0 rtype eow@openssh.com \<mailto:eow@openssh.com\> reply 0 debug1: channel 0:  
> free: client-session, nchannels 1 Transferred: sent 2776, received 3416 bytes, in 0.9 seconds Bytes per second: sent  
> 2926.2, received 3600.8 debug1: Exit status 0 |
> 
> Only via Ansible, git cloning is failing.
> 
> \>fatal: [192.168.99.105]: FAILED! =\> {"changed": false, "cmd": ["/usr/bin/git", "fetch", "--tags", "origin"], "msg":  
> "Failed to download remote objects and refs: ||Load key \"/home/mrajaa/.ssh/id\_rsa.pub\": \*invalid format\r\ngit@gitlab.com \<mailto:ngit@gitlab.com\>: 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"} |
> 
> My git clone task is like this,  
> ------------------------------------------------------------------------------------------------------------------------
> 
> name: use git to clone myconfigs  
> git:  
> dest: “{{ myconfig\_dir }}”  
> repo: “{{ dotfile\_repo }}”  
> accept\_hostkey: yes  
> key\_file: “{{ ssh\_key }}”  
> force: no #this will not forcefully clone, if there are some local modifications  
> ignore\_errors: true  
> ```

The value for key\_file expects the path to the \*private\* SSH key.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [June 21, 2020, 8:46am UTC](https://forum.ansible.com/t/git-clone-failing-only-via-ansible-working-via-cmdline/33227/3 "2020-06-21T08:46:50Z")

</div>

> Hello,
> 
> When I git clone from cmdline, I am able to clone successfully. But when I do the same thing via, Ansible, something is going wrong.
> 
> ```auto
> git clone git@gitlab.com:xxxx/yyyy.git
> Cloning into 'yyyy'...
> remote: Enumerating objects: 223, done.
> remote: Counting objects: 100% (223/223), done.
> remote: Compressing objects: 100% (164/164), done.
> remote: Total 223 (delta 21), reused 175 (delta 6), pack-reused 0
> Receiving objects: 100% (223/223), 667.18 KiB | 204.00 KiB/s, done.
> Resolving deltas: 100% (21/21), done.
> 
> ```
> 
> Also, following is fine.
> 
> ```auto
> ssh -vT [git@gitlab.com](mailto:git@gitlab.com)
> [...]
> debug1: Sending environment.
> debug1: Sending env LANG = en_US.UTF-8
> **Welcome to GitLab** , @mukuntharajaa!
> debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
> debug1: client_input_channel_req: channel 0 rtype [eow@openssh.com](mailto:eow@openssh.com) reply 0
> debug1: channel 0: free: client-session, nchannels 1
> Transferred: sent 2776, received 3416 bytes, in 0.9 seconds
> Bytes per second: sent 2926.2, received 3600.8
> debug1: Exit status 0
> 
> ```
> 
> Only via Ansible, git cloning is failing.
> 
> ```auto
> fatal: [192.168.99.105]: FAILED! => {"changed": false, "cmd": ["/usr/bin/git", "fetch", "--tags", "origin"], "msg": "Failed to download remote objects and refs: Load key \"/home/mrajaa/.ssh/id_rsa.pub\": **invalid format\r\[ngit@gitlab.com](mailto:ngit@gitlab.com): 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"}
> 
> ```
> 
> My git clone task is like this,
> 
> * * *
> 
> name: use git to clone myconfigs  
> git:  
> dest: “{{ myconfig\_dir }}”  
> repo: “{{ dotfile\_repo }}”  
> accept\_hostkey: yes  
> key\_file: “{{ ssh\_key }}”  
> force: no #this will not forcefully clone, if there are some local modifications  
> ignore\_errors: true
> 
> ```auto
> 
> I even have task to add ssh keys.
> 
> ```
> 
> - name: Add ssh keys to ssh-agent  
> authorized\_key:  
> user: “{{ username }}”  
> state: present  
> key: “{{ lookup(‘file’, item) }}”  
> with\_fileglob:
> - “{{ home\_dir }}.ssh/\*.pub”
> 
> ```auto
> 
> ```

Note that your task name is a bit misleading, as it add keys to a file. Nothing is done with agents.

---

<div class="post-metadata">

**Author:** ![Mukuntha\_rajaa](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@Mukuntha\_rajaa](https://forum.ansible.com/u/Mukuntha_rajaa)\
**Post date:** [June 21, 2020, 10:10am UTC](https://forum.ansible.com/t/git-clone-failing-only-via-ansible-working-via-cmdline/33227/4 "2020-06-21T10:10:13Z")

</div>

Thanks. That worked !!! I missed to see this word in document. My bad ☹  
"
