Provision Ubuntu 16.04 VMs on clouds using Ansible

by (October 26, 2016)

Posted in Provision  Tags:AWS, GCP, Azure, Ansible, Ubuntu

Ansible to handle Ubuntu Xenial

What is the issue?

In Ubuntu 16.04 Xenial python version 2.7 is removed from default images. And Ansible still doesn’t support python3.

So when you will try to run some playbook against freshly started Ubuntu 16.04 EC2 you will get an error.

How to fix it?

You just need to install python-simplejson. From DevOps sight manual is not an option. How can we automate it?

Using raw

You can add this construction to your playbook:

- hosts: all
  gather_facts: False

  - name: install python 2
    raw: test -e /usr/bin/python || (apt -y update && apt install -y python-simplejson)

But there is more elegant way of doing it in true DevOps clouds style…

Using Cloud-Init

Many cloud providers, i.e. AWS, GCP, Azure support Cloud-Init a great tool to automate cloud instances.

We can use it to solve this problem:


- python-simplejson

Using ec2 module and user-data

When you are starting AWS EC2 instance using Ansible you can use user_data option of ec2 module:

- name: create ec2 instance
    region: ""
    user_data: |
      - python-simplejson

Let us know!

Contact details:


Services you are interested in: