apt module failing on Ubuntu 14.04 LTS

Anisble 1.5.4 running from Ubuntu 13.10, “virgin” install of Ubuntu 14.04 LTS, the very first task of my playbook fails:

  • name: apt-get update
    apt: update_cache=yes

TASK: [common | apt-get update] ***********************************************
<1xx.xx.xx.xx> ESTABLISH CONNECTION FOR USER: ubuntu
<1xx.xx.xx.xx> REMOTE_MODULE apt update_cache=yes
<1xx.xx.xx.xx> EXEC [‘ssh’, ‘-C’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/home/miketitus/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=22’, ‘-o’, ‘IdentityFile=creds/phantom-test’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘User=ubuntu’, ‘-o’, ‘ConnectTimeout=10’, ‘1xx.xx.xx.xx’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1397851850.37-160665359287307 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1397851850.37-160665359287307 && echo $HOME/.ansible/tmp/ansible-tmp-1397851850.37-160665359287307’”]
<1xx.xx.xx.xx> PUT /tmp/tmprbQMHK TO /home/ubuntu/.ansible/tmp/ansible-tmp-1397851850.37-160665359287307/apt
<1xx.xx.xx.xx> EXEC [‘ssh’, ‘-C’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/home/miketitus/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=22’, ‘-o’, ‘IdentityFile=creds/phantom-test’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘User=ubuntu’, ‘-o’, ‘ConnectTimeout=10’, ‘1xx.xx.xx.xx’, ‘/bin/sh -c 'sudo -k && sudo -H -S -p “[sudo via ansible, key=jdrwkofumuslbxgkogxvwgixuhloymos] password: " -u root /bin/sh -c '”'“'echo SUDO-SUCCESS-jdrwkofumuslbxgkogxvwgixuhloymos; /usr/bin/python /home/ubuntu/.ansible/tmp/ansible-tmp-1397851850.37-160665359287307/apt; rm -rf /home/ubuntu/.ansible/tmp/ansible-tmp-1397851850.37-160665359287307/ >/dev/null 2>&1'”'"''’]
failed: [1xx.xx.xx.xx] => {“failed”: true, “item”: “”}
msg: Could not import python modules: apt, apt_pkg. Please install python-apt package.

This issue has been fixed in the ‘devel’ branch, and will appear in 1.6

https://github.com/ansible/ansible/pull/6518

In the interim you may have to use the ‘raw’ module to install python-apt:

  • name: install python-apt
    raw: apt-get update && apt-get install python-apt -y -q