does the core git module always make remote request?

40 views
Skip to first unread message

nrser

unread,
Feb 18, 2015, 6:43:19 AM2/18/15
to ansible...@googlegroups.com
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:

imac:ansible nrser$ time ansible-playbook -v all.yaml

PLAY [all] ********************************************************************

GATHERING FACTS ***************************************************************
ok: [localhost]

TASK: [dock | clean dock] *****************************************************
changed: [localhost] => {"changed": true, "cmd": "PYTHONIOENCODING=utf-8 ~/dev/gh/kcrawford/dockutil/scripts/dockutil --remove all", "delta": "0:00:00.092592", "end": "2015-02-18 19:33:29.696049", "rc": 0, "start": "2015-02-18 19:33:29.603457", "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.100975", "end": "2015-02-18 19:33:29.917863", "item": {"path": "/Applications", "view": "list"}, "rc": 0, "start": "2015-02-18 19:33:29.816888", "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.097106", "end": "2015-02-18 19:33:30.092658", "item": {"path": "~/", "view": "list"}, "rc": 0, "start": "2015-02-18 19:33:29.995552", "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.097929", "end": "2015-02-18 19:33:30.265187", "item": {"path": "~/Downloads", "sort": "datemodified", "view": "list"}, "rc": 0, "start": "2015-02-18 19:33:30.167258", "stderr": "", "stdout": "", "warnings": []}

PLAY RECAP ********************************************************************
localhost                  : ok=4    changed=2    unreachable=0    failed=0


real 0m1.215s
user 0m0.653s
sys 0m0.418s

 

Brian Coca

unread,
Feb 18, 2015, 10:00:03 AM2/18/15
to ansible...@googlegroups.com
can you show the git task?




--
Brian Coca

nrser

unread,
Feb 20, 2015, 5:36:58 AM2/20/15
to ansible...@googlegroups.com
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: "g...@github.com:{{ owner }}/{{ name }}"
    dest: "{{ gh_root }}/{{ owner }}/{{ name }}"
    update: "{{ update | default(no) }}"

Dick Davies

unread,
Feb 20, 2015, 6:01:56 AM2/20/15
to ansible list
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).
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/6a4ed7dc-8186-403a-a4a7-c7be41929718%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

nrser

unread,
Feb 20, 2015, 6:14:29 AM2/20/15
to ansible...@googlegroups.com, di...@hellooperator.net
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:

---
dependencies:
  - role: github_repo
    owner: kcrawford
    name: dockutil
    version: 2.0.2

i can understand always hitting the wire if the version isn't set (which i would assume to indicate you want HEAD), but i dodn't understand the network access when the version is provided and the local copy is already at that version. it even does so when `version` is set to a specific commit, which, from my understanding of git would make needed a change impossible (the commit could be gone from the remote repo, but it should not be possible for that same commit hash to point to a different state of the repo, right?).

as i said before, given the nature of git i can understand there being some corner cases where an update is necessary to have the correct checkout - for a tag, maybe the it now points to a different commit - but these seems like rare instances to pay 25 seconds per repo for by default.

Dick Davies

unread,
Feb 20, 2015, 9:52:19 AM2/20/15
to nrser, ansible list
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.
Reply all
Reply to author
Forward
0 new messages