# does the core git module always make remote request?

**URL:** <https://forum.ansible.com/t/does-the-core-git-module-always-make-remote-request/17547>\
**Category:** Ansible Project\
**Created:** [February 18, 2015, 11:43am UTC](https://forum.ansible.com/t/does-the-core-git-module-always-make-remote-request/17547 "2015-02-18T11:43:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nrser](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nrser](https://forum.ansible.com/u/nrser)\
**Post date:** [February 18, 2015, 11:43am UTC](https://forum.ansible.com/t/does-the-core-git-module-always-make-remote-request/17547/1 "2015-02-18T11:43:19Z")

</div>

hey everyone, i just got started with ansible today and have a question about the core git module - does it always make remote requests when a repo is specified, even when it’s in the desired state?

i ask because ansible is taking considerable time at that step, which is annoying during this early fast iteration and is going to get _really_ annoying once i have 20-30 repos in there. i haven’t dug into the git module code, but i can only realistically attribute the delay to a remote request - the git module correctly reports that _nothing has changed_, but a run that includes the repo dependency takes 25 seconds, versus 1.2 seconds when the dependency is commented out (see output dumps at bottom).

i understand that remote requests might be necessary to make _absolutely sure_ that things are correct and maybe deal with some nasty edge cases, but for obvious reasons i would like to have the module not contact the remote if the repo is already present in the specified state. any way to get this behavior?

**with the git repo:**

> imac:ansible nrser$ time ansible-playbook -v all.yaml
> 
> PLAY [all] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> ok: [localhost]
> 
> TASK: [github\_repo | clone kcrawford/dockutil from github] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> ok: [localhost] =\> {“after”: “7e7b56dae7a118c256748c2f69c82b912d64c6e2”, “before”: “7e7b56dae7a118c256748c2f69c82b912d64c6e2”, “changed”: false}
> 
> TASK: [dock | clean dock] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> changed: [localhost] =\> {“changed”: true, “cmd”: “PYTHONIOENCODING=utf-8 ~/dev/gh/kcrawford/dockutil/scripts/dockutil --remove all”, “delta”: “0:00:00.095622”, “end”: “2015-02-18 19:33:21.744730”, “rc”: 0, “start”: “2015-02-18 19:33:21.649108”, “stderr”: “”, “stdout”: “”, “warnings”: }
> 
> TASK: [dock | add apps] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> skipping: [localhost] =\> (item=apps)
> 
> TASK: [dock | add folders] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> changed: [localhost] =\> (item={‘path’: ‘/Applications’, ‘view’: ‘list’}) =\> {“changed”: true, “cmd”: “PYTHONIOENCODING=utf-8 ~/dev/gh/kcrawford/dockutil/scripts/dockutil --add ‘/Applications’ --view list --display folder --sort name”, “delta”: “0:00:00.096044”, “end”: “2015-02-18 19:33:21.943452”, “item”: {“path”: “/Applications”, “view”: “list”}, “rc”: 0, “start”: “2015-02-18 19:33:21.847408”, “stderr”: “”, “stdout”: “”, “warnings”: }
> 
> changed: [localhost] =\> (item={‘path’: ‘~/’, ‘view’: ‘list’}) =\> {“changed”: true, “cmd”: “PYTHONIOENCODING=utf-8 ~/dev/gh/kcrawford/dockutil/scripts/dockutil --add ‘~/’ --view list --display folder --sort name”, “delta”: “0:00:00.097483”, “end”: “2015-02-18 19:33:22.112191”, “item”: {“path”: “~/”, “view”: “list”}, “rc”: 0, “start”: “2015-02-18 19:33:22.014708”, “stderr”: “”, “stdout”: “”, “warnings”: }
> 
> changed: [localhost] =\> (item={‘sort’: ‘datemodified’, ‘path’: ‘~/Downloads’, ‘view’: ‘list’}) =\> {“changed”: true, “cmd”: “PYTHONIOENCODING=utf-8 ~/dev/gh/kcrawford/dockutil/scripts/dockutil --add ‘~/Downloads’ --view list --display folder --sort datemodified”, “delta”: “0:00:00.099095”, “end”: “2015-02-18 19:33:22.288923”, “item”: {“path”: “~/Downloads”, “sort”: “datemodified”, “view”: “list”}, “rc”: 0, “start”: “2015-02-18 19:33:22.189828”, “stderr”: “”, “stdout”: “”, “warnings”: }
> 
> PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> localhost : ok=5 changed=2 unreachable=0 failed=0
> 
> real 0m25.046s
> 
> user 0m0.810s
> 
> sys 0m0.584s

**without the git repo:**

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 18, 2015, 3:00pm UTC](https://forum.ansible.com/t/does-the-core-git-module-always-make-remote-request/17547/2 "2015-02-18T15:00:00Z")

</div>

can you show the git task?

---

<div class="post-metadata">

**Author:** ![nrser](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nrser](https://forum.ansible.com/u/nrser)\
**Post date:** [February 20, 2015, 10:36am UTC](https://forum.ansible.com/t/does-the-core-git-module-always-make-remote-request/17547/3 "2015-02-20T10:36:57Z")

</div>

it looks like the parameter i was looking for was `update=no`, which seems to prevent the remote request. something like:

- name: clone {{ owner }}/{{ name }} from github  
git:  
repo: “[git@github.com](mailto:git@github.com):{{ owner }}/{{ name }}”  
dest: “{{ gh\_root }}/{{ owner }}/{{ name }}”  
update: “{{ update | default(no) }}”

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [February 20, 2015, 11:01am UTC](https://forum.ansible.com/t/does-the-core-git-module-always-make-remote-request/17547/4 "2015-02-20T11:01:53Z")

</div>

Be a bit careful with that - that repo isn't going to update once it's checked  
out ( a bit like 'state=present' on a RPM resource).  
That might be what you want, of course 🙂

I found a good compromise of network activity vs. control was to use the  
"version=" parameter and point at a tag/commit. That's easy enough to set  
as a var and makes sure I'm getting the code I want, rather than HEAD  
(especially important if you have handlers attached to that task that you  
don't want firing every run).

---

<div class="post-metadata">

**Author:** ![nrser](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@nrser](https://forum.ansible.com/u/nrser)\
**Post date:** [February 20, 2015, 11:14am UTC](https://forum.ansible.com/t/does-the-core-git-module-always-make-remote-request/17547/5 "2015-02-20T11:14:29Z")

</div>

it was doing a remote request even when the `version` parameter was set _and_ the local copy was at that tag. here’s what was in the meta file that triggered it:

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [February 20, 2015, 2:52pm UTC](https://forum.ansible.com/t/does-the-core-git-module-always-make-remote-request/17547/6 "2015-02-20T14:52:12Z")

</div>

This all rings a vague bell, I ended up going through the ansible module code  
to figure out what it was playing at (I gave up and just built the code into an  
RPM, hence my answer being a bit outdated - sorry about that).

I've seen similar issues with get\_url (which suffers from the same problem).

One way to get around it is to set "dest=" to a folder named after the commit  
you want.  
Combined with update=no you'll save the time tax on subsequent runs when  
the commit is constant, but be able to check out fresh code when you update  
the desired commit var.
