#65687·ansible

get_url in check_mode reports changed status when there is nothing to change

Author: rafal-krypaCreated Dec 10, 2019Updated Sep 24, 2026
LabelsmodulebugP3needs_verifiedaffects_2.9
SUMMARY

When using get_url module with url argument and dest argument pointing to a file, running in check mode will always cause status changed even if the local file is already downloaded and identical to the remote file.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

get_url

ANSIBLE VERSION
ansible 2.9.1
  config file = /data/src/mediator/mediator-ansible/ansible.cfg
  configured module search path = [u'/home/r.krypa/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.17 (default, Oct 19 2019, 23:36:22) [GCC 9.2.1 20191008]
CONFIGURATION
OS / ENVIRONMENT

Debian testing with ansible package installed from ansible PPA for Ubuntu Disco

STEPS TO REPRODUCE

Minimal playbook, saved as get_url.yml:

yaml
- hosts: localhost
  gather_facts: no
  tasks:
  - get_url:
      url: https://github.githubassets.com/favicon.ico
      dest: /tmp/favicon.ico

Running for the first time, it will download the file and correctly set status as changed:

bash
$ ansible-playbook get_url.yml 

PLAY [localhost] ***************************************************************

TASK [get_url] *****************************************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

When running for the second time, there are no changes to apply:

bash
$ ansible-playbook get_url.yml 

PLAY [localhost] ***************************************************************

TASK [get_url] *****************************************************************
ok: [localhost]

PLAY RECAP *********************************************************************
localhost: ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

But when run in check mode, it detects changes:

bash
$ ansible-playbook get_url.yml --check -v

PLAY [localhost] ***************************************************************

TASK [get_url] *****************************************************************
changed: [localhost] => {"changed": true, "checksum_dest": "07ed688be6d6288a669778f65f7eccdd96770925", "checksum_src": "da39a3ee5e6b4b0d3255bfef95601890afd80709", "dest": "/tmp/favicon.ico", "elapsed": 0, "gid": 1000, "group": "r.krypa", "mode": "0644", "msg": "OK (6518 bytes)", "owner": "r.krypa", "size": 6518, "src": "/home/r.krypa/.ansible/tmp/ansible-tmp-1575979280.66-100488643343463/tmplpOjyR", "state": "file", "uid": 1000, "url": "https://github.githubassets.com/favicon.ico"}

PLAY RECAP *********************************************************************
localhost                  : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Interesting part of the supposedly changed run in check mode is "checksum_src": "da39a3ee5e6b4b0d3255bfef95601890afd80709". This is a checksum of an empty string (the same one can be produced by sha1sum </dev/null). It seems that get_url module compares checksum of an existing file on disk against checksum of an empty string and detects a change based on that comparison.

EXPECTED RESULTS

If a playbook runs in normal mode and doesn't perform any changes, it shouldn't report changes when run in check mode.

ACTUAL RESULTS

Changes are reported by get_url module because in check mode it seems to compare empty string with existing file on the host.