apt call always returns changed

I have this in a playbook

  • name: Install needed packages
    apt: pkg={{ item }} state=latest
    with_items:
  • libxml2-dev
  • libxslt-dev
  • memcached
  • uwsgi

Every single time it runs, it reports changed…
output with -vvvv

TASK: [Install needed packages] ***********************************************
<sp-web.clienthost.pw>
<sp-web.clienthost.pw> state=latest pkg=libxml2-dev,libxslt-dev,memcached,uwsgi
<sp-web.clienthost.pw> ConnectTimeout=10 PasswordAuthentication=no KbdInteractiveAuthentication=no User=root ControlPath=/home/francisco/.ansible/cp/ansible-ssh-%h-%p-%r PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey ControlMaster=auto Port=2222 ControlPersist=60s
<sp-web.clienthost.pw>
<sp-web.clienthost.pw> ConnectTimeout=10 PasswordAuthentication=no ‘LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1424237732.24-109662245491931/apt; rm -rf /root/.ansible/tmp/ansible-tmp-1424237732.24-109662245491931/ >/dev/null 2>&1’ KbdInteractiveAuthentication=no User=root ControlPath=/home/francisco/.ansible/cp/ansible-ssh-%h-%p-%r PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey ControlMaster=auto Port=2222 ControlPersist=60s
changed: [sp-web.clienthost.pw] => (item=libxml2-dev,libxslt-dev,memcached,uwsgi) => {“changed”: true, “item”: “libxml2-dev,libxslt-dev,memcached,uwsgi”, “stderr”: “”, “stdout”: “Reading package lists…\nBuilding dependency tree…\nReading state information…\nlibxslt1-dev is already the newest version.\n0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.\n”}

Any ideas why it keeps reporting “changed”.

I tried checking if apt upgrade even reports anything in the target machine and it doesn’t.

I have this in a playbook

  • name: Install needed packages
    apt: pkg={{ item }} state=latest
    with_items:
  • libxml2-dev
  • libxslt-dev
  • memcached
  • uwsgi

I can see same behaviour for following play which is quite similar

TODO: This is marked as changed even if no package is installed

  • name: Install dev ubuntu packages for jenkins
    sudo: yes
    apt:
    pkg={{item}}
    state=present
    with_items: [‘libxml2-dev’, ‘libxslt-dev’, ‘zlib1g-dev’]
    tags: install

funny thing is that it doesn’t happen for other packages. only for these 3.

After some troubleshooting problem looks to be in libxslt-dev package

caracal:rsd_env_setup (master*) $ ansible -m apt -a ‘pkg=libxslt-dev state=present’ opsci-server -s -vvv
<opsci.rsd.com> ESTABLISH CONNECTION FOR USER: rsd
<opsci.rsd.com> REMOTE_MODULE apt pkg=libxslt-dev state=present
<opsci.rsd.com> EXEC ssh -C -tt -q -o ControlPersist=15m -F /Users/haad/.ansible/ssh_config -o ControlPath=“/Users/haad/.ansible/cp/ansible-ssh-%h-%p-%r” -o StrictHostKeyChecking=no -o Port=22 -o IdentityFile=“/Users/haad/.ssh/id_rsa” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=rsd -o ConnectTimeout=19 opsci.rsd.com /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1424265035.78-99667925086072 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1424265035.78-99667925086072 && echo $HOME/.ansible/tmp/ansible-tmp-1424265035.78-99667925086072’
<opsci.rsd.com> PUT /var/folders/yq/_h9bmb6x1qxb7p4_w5xhkgx80000gn/T/tmpg9KHmA TO /home/rsd/.ansible/tmp/ansible-tmp-1424265035.78-99667925086072/apt
<opsci.rsd.com> EXEC ssh -C -tt -q -o ControlPersist=15m -F /Users/haad/.ansible/ssh_config -o ControlPath=“/Users/haad/.ansible/cp/ansible-ssh-%h-%p-%r” -o StrictHostKeyChecking=no -o Port=22 -o IdentityFile=“/Users/haad/.ssh/id_rsa” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=rsd -o ConnectTimeout=19 opsci.rsd.com /bin/sh -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=cljxvustcsbxbaozbgaskderzvnjkymy] password: " -u root /bin/sh -c '”’“‘echo SUDO-SUCCESS-cljxvustcsbxbaozbgaskderzvnjkymy; LANG=C LC_CTYPE=C /usr/bin/python /home/rsd/.ansible/tmp/ansible-tmp-1424265035.78-99667925086072/apt; rm -rf /home/rsd/.ansible/tmp/ansible-tmp-1424265035.78-99667925086072/ >/dev/null 2>&1’”‘"’’
opsci-server | success >> {
“changed”: true,
“stderr”: “”,
“stdout”: “Reading package lists…\nBuilding dependency tree…\nReading state information…\nlibxslt1-dev is already the newest version.\n0 upgraded, 0 newly installed, 0 to remove and 65 not upgraded.\n”
}

caracal:rsd_env_setup (master*) $ ansible -m apt -a ‘pkg=libxml2-dev state=present’ opsci-server -s -vvv
<opsci.rsd.com> ESTABLISH CONNECTION FOR USER: rsd
<opsci.rsd.com> REMOTE_MODULE apt pkg=libxml2-dev state=present
<opsci.rsd.com> EXEC ssh -C -tt -q -o ControlPersist=15m -F /Users/haad/.ansible/ssh_config -o ControlPath=“/Users/haad/.ansible/cp/ansible-ssh-%h-%p-%r” -o StrictHostKeyChecking=no -o Port=22 -o IdentityFile=“/Users/haad/.ssh/id_rsa” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=rsd -o ConnectTimeout=19 opsci.rsd.com /bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1424265055.72-134679118481702 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1424265055.72-134679118481702 && echo $HOME/.ansible/tmp/ansible-tmp-1424265055.72-134679118481702’
<opsci.rsd.com> PUT /var/folders/yq/_h9bmb6x1qxb7p4_w5xhkgx80000gn/T/tmpR6qy_K TO /home/rsd/.ansible/tmp/ansible-tmp-1424265055.72-134679118481702/apt
<opsci.rsd.com> EXEC ssh -C -tt -q -o ControlPersist=15m -F /Users/haad/.ansible/ssh_config -o ControlPath=“/Users/haad/.ansible/cp/ansible-ssh-%h-%p-%r” -o StrictHostKeyChecking=no -o Port=22 -o IdentityFile=“/Users/haad/.ssh/id_rsa” -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=rsd -o ConnectTimeout=19 opsci.rsd.com /bin/sh -c ‘sudo -k && sudo -H -S -p “[sudo via ansible, key=dlcbjvxflyxkbuoiaomhxeyyczmpstws] password: " -u root /bin/sh -c '”’“‘echo SUDO-SUCCESS-dlcbjvxflyxkbuoiaomhxeyyczmpstws; LANG=C LC_CTYPE=C /usr/bin/python /home/rsd/.ansible/tmp/ansible-tmp-1424265055.72-134679118481702/apt; rm -rf /home/rsd/.ansible/tmp/ansible-tmp-1424265055.72-134679118481702/ >/dev/null 2>&1’”‘"’’
opsci-server | success >> {
“changed”: false
}

So I’m sorry for spaming but I cracked it problem is that there is no package called libxslt-dev that’s just an alias to libxslt1-dev and if you use former name it will print a node to stdout. Which will trigger the change.

opsci:~ $ sudo apt-get install libxslt-dev
Reading package lists… Done
Building dependency tree
Reading state information… Done
Note, selecting ‘libxslt1-dev’ instead of ‘libxslt-dev’ <<<< note
libxslt1-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 65 not upgraded.

opsci:~ $ sudo apt-get install libxslt1-dev
Reading package lists… Done
Building dependency tree
Reading state information… Done
libxslt1-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 65 not upgraded.

this happens with virtual packages, as they do not appear as
installed, but then when apt runs the package that provides the
virtual slot is found and no change is made, but it was detected as
such.