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

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 :slight_smile: )

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!

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!