If you ever get an error while trying to provision an Ubuntu server with Ansible, check whether it’s not a case of a mismatched Python interpreter.

Today we wanted to provision one of our Ubuntu servers with Ansible and got an error: /bin/sh: 1: /usr/bin/python: not found\r\n
After a quick search it turned out you need to explicitly provide a path to the python3 interpreter, which is installed by default (instead of the Python 2 version):

ip.ip.ip.ip ansible_user=ubuntu ansible_python_interpreter=/usr/bin/python3

Seems easy, so we did it and retried the playbook. Then we hit another error: Could not find aptitude. Please ensure it is installed.
Ubuntu does not come with aptitude by default any more (at least on AWS; on Vagrant the playbook ran fine), and it’s used by Ansible (link to the issue on Github). It turned out we can solve this by defining a pre-task in the playbook to install it:

  - name: 'install aplitude'
    raw: sudo apt-get install -y aptitude
    become: true
    become_user: root
    become_method: sudo

Today’s Developers’ Notes were prepared by Łukasz, our Web Application Development Team Leader. Stay tuned, because there’s more where this came from!