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.

3 thoughts on “How to add a mysql user with REPLICATION SLAVE privileges using Ansible

  1. Thanks, made some changes:
    – added state=present
    – change user option to name (as that is the correct name of the option)
    – added quotes around the whole priv option
    – used the Yaml multiline syntax to improve readability
    – added a conditional as I use the same role to provision master and slave servers

    – name: ensure a slave user is created on master db
    mysql_user: >
    name={{ database.slave_user }}
    password={{ database.password }}
    priv=”*.*:REPLICATION SLAVE”
    when: database.master_or_slave == ‘master’

  2. I hit the same issue upon executing my custom module with the arguments passed as “arg1: val1” and so on. However, changing it to “arg1=val1” worked (equal to instead of colon worked)!

    Hope it helps someone!

Leave a Reply