# apt module is giving me some very strange behavior: sometimes it works, sometimes it says python-apt is not installed

**URL:** <https://forum.ansible.com/t/apt-module-is-giving-me-some-very-strange-behavior-sometimes-it-works-sometimes-it-says-python-apt-is-not-installed/14962>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [April 7, 2014, 7:42pm UTC](https://forum.ansible.com/t/apt-module-is-giving-me-some-very-strange-behavior-sometimes-it-works-sometimes-it-says-python-apt-is-not-installed/14962 "2014-04-07T19:42:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris\_d1](https://avatars.discourse-cdn.com/v4/letter/c/a6a055/32.png) [@chris\_d1](https://forum.ansible.com/u/chris_d1)\
**Post date:** [April 7, 2014, 7:42pm UTC](https://forum.ansible.com/t/apt-module-is-giving-me-some-very-strange-behavior-sometimes-it-works-sometimes-it-says-python-apt-is-not-installed/14962/1 "2014-04-07T19:42:20Z")

</div>

hi everyone,

i’m really digging ansible so far, but I keep running into this one strange issue.

I have a couple different roles, and for now they all target the same host. In a common role, it ansible uses the apt module to install some apt packages like so:

- name: install common apt packages  
apt: pkg={{ item }} state=installed update\_cache=yes  
with\_items: apt\_packages

This bit works well, all the packages are installed as I would expect.

Then in another role (which uses a different vars file, so the apt\_packages variable is different), I have this:

- name: install application server apt packages  
sudo: yes  
apt: pkg={{ item }} state=installed  
with\_items: apt\_packages  
notify: install libjpeg

Which fails with the following:

failed: [host] =\> (item= \<\>) =\> {“failed”: true, “item”: “libmysqlclient-dev,libmysqlclient18,libjpeg8-dev,libfreetype6-dev,zlib1g-dev,libtiff4-dev”}  
msg: Could not import python modules: apt, apt\_pkg. Please install python-apt package.

Which is weird because…  
a) The python-apt module is installed  
b) I just used the ansible apt module in a previous role and it worked just fine  
c) running the straight command like this:

- name: install appserver apt packages  
sudo: yes  
command: apt-get install -y libjpeg-dev libfreetype6-dev zlib1g-dev libtiff4-dev libjpeg-dev libmysqlclient-dev

works fine. But I’d like to use the ansible apt module in order to get the notify functionality to work so i don’t have to rebuild libjpeg every time (ugly python/ubuntu/PIL bug workaround…don’t ask 🙂 )

If anyone sees anything that I’m doing wrong, let me know…I’m pretty new to ansible so it may be obvious. This is using ansible 1.4.3 and ubuntu 12.04 and python 2.7.

Thanks!

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [April 8, 2014, 3:35pm UTC](https://forum.ansible.com/t/apt-module-is-giving-me-some-very-strange-behavior-sometimes-it-works-sometimes-it-says-python-apt-is-not-installed/14962/2 "2014-04-08T15:35:41Z")

</div>

Is there any chance you could try this with the 1.5.4 release, or with the most up to date devel branch to see if it’s still an issue? If so, please open an issue on github so we can keep track of it.

Thanks!
