# Using shell or command to do  git operation fails half the time

**URL:** <https://forum.ansible.com/t/using-shell-or-command-to-do-git-operation-fails-half-the-time/26188>\
**Category:** Ansible Project\
**Created:** [December 1, 2017, 7:55pm UTC](https://forum.ansible.com/t/using-shell-or-command-to-do-git-operation-fails-half-the-time/26188 "2017-12-01T19:55:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Bushey](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@Michael\_Bushey](https://forum.ansible.com/u/Michael_Bushey)\
**Post date:** [December 1, 2017, 7:55pm UTC](https://forum.ansible.com/t/using-shell-or-command-to-do-git-operation-fails-half-the-time/26188/1 "2017-12-01T19:55:20Z")

</div>

I am doing a git fetch (also git merge master) on the remote machines. It seems random whether it will work or not. I get errors like: “error fetching identities for protocol 2: communication with agent failed” or “fatal: ‘ef’ does not appear to be a git repository\nfatal: Could not read from remote repository.\n\nPlease make sure you have the correct access rights\nand the repository exists.”

I can manually ssh into the server and run a “git fetch” 100% of the time.

In the Ansible playbook I can do a “ssh-add -l” and see the key it should be using the step before the “Could not read from remote repository.” error. The git server is Bitbucket v5.4.0.

Any ideas?

---

<div class="post-metadata">

**Author:** ![Michael\_Bushey](https://avatars.discourse-cdn.com/v4/letter/m/e9bcb4/32.png) [@Michael\_Bushey](https://forum.ansible.com/u/Michael_Bushey)\
**Post date:** [December 5, 2017, 11:27pm UTC](https://forum.ansible.com/t/using-shell-or-command-to-do-git-operation-fails-half-the-time/26188/2 "2017-12-05T23:27:57Z")

</div>

Sourcing this script fixes the problem:  
[https://github.com/wwalker/ssh-find-agent](https://github.com/wwalker/ssh-find-agent)
