Provisioning Ubuntu 16 servers with Ansible

If you have tried to use Ansible to provision a bare Ubuntu 16 server you may have found an error similar to this:

TASK [setup] *******************************************************************
fatal: [foo]: FAILED! => {"changed": false, "failed": true, "module_stderr": "", "module_stdout": "/bin/sh: 1: /usr/bin/python: not found\r\n", "msg": "MODULE FAILURE", "parsed": false}

This is caused because Ansible still does not support Python3 (… yeah …) and Ubuntu16 ships with Python3 only.
The temporary “hacky” solution is to install a Python2 interpreter.

If you are using AWS you can add a bash script similar to this to your userdata and you will have your server ready to go

#!/usr/bin/env bash
test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)

If your server is already running you can always SSH into the box and run this command but if you have dozens or even hundreds of them this is not a great idea. Instead, we can use this small Ansible script to target all our Xenials:

- hosts: xenials 
  # This is very important as otherwise a setup task will be executed
  # to gather the server facts and this will fail as there is no Python2 yet
  gather_facts: false
  become: true 
    - name: install python 2
      raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)

And there are some other small issues. For instance, aptitude is not installed by default either so the Ansible apt module will fail.

Apparently, Ansible will soon support Python3 but if you want to start using Ubuntu 16 with Ansible in November 2016 you will face some issues! Consider yourself warned!

You may also like...