git module often marked as changed even when nothing changed

23 views
Skip to first unread message

MartinBBG

unread,
Oct 28, 2019, 3:46:59 PM10/28/19
to Ansible Project
Using ansible 2.6

In our playbook, we are using the git module to checkout a specific repo. Most of the time, the playbook reports this as changed even though the repo has not changed. Sometimes it does properly report as not changed.

Here is the git module parameters:

- name: checkout our repo
  git:
    repo: "git@{{ serverurl }}:repo.git"
    dest: /opt/repofolder
    key_file: /path/.ssh/sshkey
    ssh_opts: "-o StrictHostKeyChecking=no"
    accept_hostkey: True
    update: yes
  become_user: localuser



When it reports as changed, it returns:
"after": "f35210a1d1d008e5a7abc328733cab87c06589a6",
"before": "f35210a1d1d008e5a7abc328733cab87c06589a6",
"changed": true,
"remote_url_changed": true


I've duplicated the directory and compared the entire directory. Some folders have a newer modified date. But no files were changed, with one exception, the file /opt/repofolder/.git/logs/HEAD has this added line:

f35210a1d1d008e5a7abc328733cab87c06589a6 f35210a1d1d008e5a7abc328733cab87c06589a6 localuser <loca...@computername.com> 1572275580 +0000 checkout: moving from master to master

That line gets added even when ansible reports no change. And also, we use these same settings in other playbooks for other repos and those correctly only report as changed when changed.

Any idea why this is happening?

Thanks.

Matt Martz

unread,
Oct 28, 2019, 4:06:02 PM10/28/19
to ansible...@googlegroups.com
According to the return, it states:

"remote_url_changed": true

This means that the URL for the remote is different as compared between the `repo` argument for the `git` module, and the value specified in `.git/config` within that repo.

You can compare what is in `.git/config` via the command ansible uses: `git ls-remote --get-url origin` from within `/opt/repofolder`

Past that, you would likely need additional debugging, following the code of the git module to determine why it's not the same value.



--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5a9ce4b6-0e74-4a0c-8430-6307d061dc7c%40googlegroups.com.


--
Matt Martz
@sivel
sivel.net

MartinBBG

unread,
Oct 28, 2019, 4:47:07 PM10/28/19
to Ansible Project
Thanks for the reply Matt.

You were right that the git url was different. I changed the url in .git/config and now the output of 'git ls-remote --get-url origin' matches what is in the ansible repo parameter. However, it is still reporting as Changed most of the time that I run the playbook. And remote_url_changed is still returning true on those runs.

Any idea how I could troubleshoot this further?

MartinBBG

unread,
Oct 31, 2019, 12:01:52 PM10/31/19
to Ansible Project
Actually, it looks like you were right Matt. We had some other external process that was changing that url back.
Reply all
Reply to author
Forward
0 new messages