MySQL and NodeJS Ansible install and configuration

The Trademe app is using NodeJS and MySQL so have spent the time getting those installed and configured through Ansible.

Installing MySQL

This could be a long and laborious task, especially if you are not a MySQL expert or DBA. Thankfully with Ansible there is a huge resource of playbooks that people have already written that can massively help.

The only problem I had was that MariaDB is recommended for Ubuntu now (and really for all open source work) after Oracle acquired MySQL. I did not know it even existed or what the story was but if you are keen for a good read, 10 reasons to migrate to MariaDB. Some from now on it is MariaDB.

I downloaded from Github a MySQL role authored by an Ansible guru. I did not clone it as I am not up to the pace on git yet. Using this MySQL role is a good gentle introduction to the power of roles, how they can be used to organise your Ansible work, and how easy it is to reuse other peoples work.

cd ~/ansible
wget https://github.com/geerlingguy/ansible-role-mysql/archive/master.zip
unzip master.zip
mkdir roles/mariadb
mv ansible-role-mysql-master/* roles/mariadb/

I did have to make some small changes to the files to get a later version of MariaDB installed. That’s all included in my repo. The other changes you need to make is to the defaults/main.yml file around users and passwords. This is all in the original ansible-role-mysql documentation.

Once you have made those file changes, all you need to do is include two new lines in your main playbook and run it to install and configure a very secure database server.

vi workstations.yml
...
---
- hosts: workstations
  roles:
  - mariadb
  remote_user: byron
  become: yes
...

WARNING: The only problem I had was around a peculiar error “MariaDB Plugin ‘unix_socket’ is not loaded” that has stumped many around it seems. The fix is here.

Installing NodeJS

This was easy, but along with a lot of software, you don’t want to just install the version out of the Ubuntu standard repository, you want the latest stable release.

For NodeJS that involved installing curl and getting the binary distribution via a shell command. This will help when you need to update the version and is the recommended method for installing NodeJS on Ubuntu distributions.

- name: Install curl
  apt:
  name: curl
  state: present

- name: Get nodejs from Ubuntu binary distributions repository
  shell: curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

- name: Install nodejs
  apt:
  name: nodejs
  state: present
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s