apt module reporting changes when there are none

In my Git role on Galaxy, I have the following task to install certain packages on Debian hosts:

  • name: Ensure git’s dependencies are installed (Debian).
    apt: “pkg={{ item }} state=installed”
    with_items:
  • libcurl4-gnutls-dev
  • libexpat1-dev
  • gettext
  • libz-dev
  • libssl-dev
  • build-essential

This task always reports a change, even when no new packages are installed… below is the full output when running the playbook with -vvvv (you can see the full playbook run, twice, on an Ubuntu 12.04 host, over on Travis CI):


TASK: [ansible-role-git | Ensure git's dependencies are installed (Debian).] *** 

<localhost> REMOTE_MODULE apt pkg=libcurl4-gnutls-dev,libexpat1-dev,gettext,libz-dev,libssl-dev,build-essential state=installed

<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1408937381.71-7455986615578 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1408937381.71-7455986615578 && echo $HOME/.ansible/tmp/ansible-tmp-1408937381.71-7455986615578']

<localhost> PUT /tmp/tmpUu6LUb TO /home/travis/.ansible/tmp/ansible-tmp-1408937381.71-7455986615578/apt

<localhost> EXEC /bin/sh -c 'sudo -k && sudo -H -S -p "[sudo via ansible, key=ptpgbfvujharlyicgqvfprtxbyzstkfo] password: " -u root /bin/sh -c '"'"'echo SUDO-SUCCESS-ptpgbfvujharlyicgqvfprtxbyzstkfo; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/travis/.ansible/tmp/ansible-tmp-1408937381.71-7455986615578/apt; rm -rf /home/travis/.ansible/tmp/ansible-tmp-1408937381.71-7455986615578/ >/dev/null 2>&1'"'"''

changed: [localhost] => (item=libcurl4-gnutls-dev,libexpat1-dev,gettext,libz-dev,libssl-dev,build-essential) => {"changed": true, "item": "libcurl4-gnutls-dev,libexpat1-dev,gettext,libz-dev,libssl-dev,build-essential", "stderr": "", "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\nzlib1g-dev is already the newest version.\nThe following packages were automatically installed and are no longer required:\n  git-man rsync liberror-perl libgeos-3.2.2\nUse 'apt-get autoremove' to remove them.\n0 upgraded, 0 newly installed, 0 to remove and 128 not upgraded.\n"}

Any ideas as to why Ansible would be setting “changed” to true for this? Nothing was upgraded/installed/removed… Other apt tasks seem to work just fine.

check if any of the packages is 'virtual’​

That was exactly the problem; the libz-dev package was causing the false ‘changed’ status.

$ aptitude search libz-dev
v libz-dev -
v libz-dev:i386 -

Thanks!

I've been looking at a good way to detect and prevent this, but end up with
circular dependencies, if you have an idea on how to make detection work
'correctly' I'm willing to code it.

Short of adding in some regular expressions to detect whether there were changes in the apt stdout, I’m not sure of a way that you could do this easily—and without introducing a host of other bugs :confused:

Perhaps there’s a log to tail?

both of those would require major refactoring of the code, it only tries to install if it already considers a change as needed.

Brian Coca

Timestamp the rpmdb… no, wait :slight_smile:

Did anybody find a solution to this, or was there an issue raised at all?

I think I might be experiencing this and would like to work around it if possible.