How to add a mysql user with REPLICATION SLAVE privileges using Ansible

I just wanted to add a user to our database with REPLICATION SLAVE privileges. The Ansible module docs suggest that would do this:

mysql_user: user="replication_user" host="%" password="longpass" priv=*.*:REPLICATION SLAVE

However you get an error messages saying “this module requires key=value arguments”. The error was caused by the space between REPLICATION and SLAVE. The answer is to put the privilege in quotes:

mysql_user: user="replication_user" host="%" password="longpass" priv=*.*:"REPLICATION SLAVE"

Hope this helps someone.

Only running command if file doesn’t exist Ansible

I have a simple build script which installs wkhtmltophf on a server. However I only want this script to be run if the software isn’t already installed. Essentially, I want an if statement or check statement in Ansible. I.e. If file doesn’t exist then run this command.

I have read the Ansible documentation multiple times and it isn’t completely clear how to do this. Anyhow, here is the answer:

- name: If file don't exist run command
  command: /root/ creates=/usr/bin/wkhtmltopdf

This is command say “This command creates this file and so if the file doesn’t exist then run the command”.

I hope this helps someone

How to batch rename files in Ubuntu

You can batch rename files in Ubuntu using the “rename” command. It should be installed by default – so no need to apt-get install.

The command is quite simple:

rename s/"SEARCH"/"REPLACE"/g *

For example renaming:




rename s/"google"/"map"/g *

Hope this helps someone.

How to import maxmind ip locations in mysql

I’m just building a map of some ip addresses and need to geolocate them. I decided to use the MaxMind database. I found these two brilliant resource without which I could not have imported the databases properly.

There are: