# apt call always returns changed

**URL:** <https://forum.ansible.com/t/apt-call-always-returns-changed/17544>\
**Category:** Ansible Project\
**Created:** [February 18, 2015, 5:36am UTC](https://forum.ansible.com/t/apt-call-always-returns-changed/17544 "2015-02-18T05:36:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francisco\_Reyes](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@Francisco\_Reyes](https://forum.ansible.com/u/Francisco_Reyes)\
**Post date:** [February 18, 2015, 5:36am UTC](https://forum.ansible.com/t/apt-call-always-returns-changed/17544/1 "2015-02-18T05:36:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Adam\_Hamsik](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@Adam\_Hamsik](https://forum.ansible.com/u/Adam_Hamsik)\
**Post date:** [February 18, 2015, 1:08pm UTC](https://forum.ansible.com/t/apt-call-always-returns-changed/17544/2 "2015-02-18T13:08:06Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![Adam\_Hamsik](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@Adam\_Hamsik](https://forum.ansible.com/u/Adam_Hamsik)\
**Post date:** [February 18, 2015, 1:11pm UTC](https://forum.ansible.com/t/apt-call-always-returns-changed/17544/3 "2015-02-18T13:11:38Z")

</div>

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](http://opsci.rsd.com)\> ESTABLISH CONNECTION FOR USER: rsd  
\<[opsci.rsd.com](http://opsci.rsd.com)\> REMOTE\_MODULE apt pkg=libxslt-dev state=present  
\<[opsci.rsd.com](http://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](http://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](http://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](http://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](http://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](http://opsci.rsd.com)\> ESTABLISH CONNECTION FOR USER: rsd  
\<[opsci.rsd.com](http://opsci.rsd.com)\> REMOTE\_MODULE apt pkg=libxml2-dev state=present  
\<[opsci.rsd.com](http://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](http://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](http://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](http://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](http://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  
}

---

<div class="post-metadata">

**Author:** ![Adam\_Hamsik](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@Adam\_Hamsik](https://forum.ansible.com/u/Adam_Hamsik)\
**Post date:** [February 18, 2015, 1:16pm UTC](https://forum.ansible.com/t/apt-call-always-returns-changed/17544/4 "2015-02-18T13:16:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 18, 2015, 2:50pm UTC](https://forum.ansible.com/t/apt-call-always-returns-changed/17544/5 "2015-02-18T14:50:36Z")

</div>

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.
