does the core git module always make remote request?

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:

can you show the git task?

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:{{ owner }}/{{ name }}”
    dest: “{{ gh_root }}/{{ owner }}/{{ name }}”
    update: “{{ update | default(no) }}”

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 :slight_smile:

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).

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:

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.