I started building out some Ubuntu 16.04 (Xenial Xerus) servers this weekend with Ansible, and was impressed by how smoothly it went. The only major issue I encountered was that Ansible requires Python 2.x, whereas Ubuntu 16.04 ships Python 3.5 by default. Fortunately, it's not too hard to work around; here's how I fixed that — and a couple of other issues specific to the servers I was building out:
Python 2
Since Ansible doesn't work with Python 3, and that's what Ubuntu 16.04 provides by default, this is the error I got when I tried running Ansible against a newly-booted server:
/usr/bin/python: not found
So I had to make this the very first Ansible play (bootstrapping the ability of Ansible to use Python 2 for the rest of its tasks, as well as for its other record keeping — like gathering facts about the server):
- name: bootstrap python 2
gather_facts: no
tasks:
- raw: sudo apt-get update -qq && sudo apt-get install -qq python2.7
And in the inventory variables (or group variables) for the server, I had to add this line (directing it to use Python 2 instead of the server's default Python):
ansible_python_interpreter: /usr/bin/python2.7
Aptitude
The next hiccup I ran into was using the Ansible apt module with the upgrade=full option. This option is implemented by using the aptitude program — which Ubuntu no longer installs by default. I was getting this error trying to use that option:
Could not find aptitude. Please ensure it is installed.
So I just tweaked my playbook to install the aptitude package first before running apt: upgrade=full:
- name: install apt requirements
become: yes
apt: pkg=aptitude
- name: update pre-installed packages
become: yes
apt: upgrade=full update_cache=yes
Mount with nobootwait
Then I started running into some minor issues that were completely unrelated to Ansible — simply changes Ubuntu had picked up between 15.10 and 16.04. The first of these was the nobootwait option for mountall (eg in /etc/fstab mountpoints). This option seems to be no longer supported — the server hung after rebooting, with this message in the syslog:
Unrecognized mount option "nobootwait" or missing value
Maybe this is just an issue with AWS EC2 instance-store volumes, but I had to change the /etc/fstab definition for the server's instance-store volume from this:
/dev/xvdb /mnt auto defaults,noatime,data=writeback,nobootwait,comment=cloudconfig 0 2
To this:
/dev/xvdb /mnt auto defaults,noatime,data=writeback,comment=cloudconfig 0 2
Java 7
The Ubuntu 16.04 repo no longer includes Java 6 or 7 — only Java 8 and 9. I got this error message trying to install Java 7:
No package matching 'openjdk-7-jdk' is available
So I first had to add a PPA for OpenJDK 7, and then could install it:
- name: register java 7 ppa
become: yes
apt_repository: repo=ppa:openjdk-r/ppa
- name: install java 7
become: yes
apt: pkg=openjdk-7-jdk
But the PPA doesn't include the timezone database, so the time formatting in our app was restricted to GMT. So I had to "borrow" the timezone data from Ubuntu 14.04:
- name: download tzdata-java
get_url:
url: http://mirrors.kernel.org/ubuntu/pool/main/t/tzdata/tzdata-java_2016d-0ubuntu0.14.04_all.deb
dest: ~/tzdata-java.deb
checksum: sha256:5131aa5219739ac58c00e18e8c9d8c5d6c63fc87236c9b5f314f7d06b46b79fb
- name: install tzdata-java
become: yes
command: dpkg --ignore-depends=tzdata -i tzdata-java.deb
That's probably going to be broken in a month or two after the next tzdata update, but it's good enough for now. Later I'll put together some Ansible tasks to build the data from source (although obviously the long-term solution is to upgrade to java 8).
Update 5/14/2016: I created a Xenial tzdata-java package to simplify the installation of Java 7 timezone data.
MySQL root
The final issue I hit was with the MySQL root user. Unlike previous versions of Ubuntu, which by default would come with 3 or 4 MySQL root users (covering all the different variations for naming your local host), and all with empty passwords, Ubuntu 16.04 comes with just a single root user — with which you can login only via MySQL's auth_socket plugin. So I was getting this error trying to login to MySQL as root the old way:
unable to connect to database, check login_user and login_password are correct or /home/me/.my.cnf has the credentials
The new way is simply to login to MySQL using the system's root user (ie sudo mysql). In Ansible tasks (such as those using the mysql_db module), this just means using the become (aka sudo) directive, and omitting the login_user and login_password options:
- name: create new database
become: yes
mysql_db: name=thedata