As we have told this so many time, we love to use ♥Ansible♥.

So, I created and another module for this besides the mysql_replication, named mysql_variables.

The purpose of this module to get/set variables from running MySQL servers, and avoid to use shell module for this, because that is a bit frustrating, and there are long commands to run.

Advertisement

For example, when you wanna to set read_only mode via shell, you can do that like this:

ansible db-secondary.bfc.kinja-ops.com -m shell -a "mysql -e 'select @@read_only'" db-secondary.bfc.kinja-ops.com | success | rc=0 >> [root@admin banyek]# ansible db-secondary.bfc.kinja-ops.com -m shell -a "mysql -e 'set global read_only=1'" db-secondary.bfc.kinja-ops.com | success | rc=0 >>

Not so neat, isn't it, eh? And I have not speak about the —user and —password variables, to this could be real annoying.

Advertisement

That's why I made this module, because it is a bit easier to use (and I like to use own toolset with the same alike problems.) and it can be act as more 'ansible like' with 'changed' tags, and so on. Like this:

[root@admin banyek]# ansible db-secondary.bfc.kinja-ops.com -m mysql_variables -a "variable=read_only" db-secondary.bfc.kinja-ops.com | success >> { "changed": false, "msg": [ [ "read_only", "OFF" ] ] } [root@admin banyek]# ansible db-secondary.bfc.kinja-ops.com -m mysql_variables -a "variable=read_only value=1" db-secondary.bfc.kinja-ops.com | success >> { "changed": true, "msg": "Variable change succeeded" }

That's it. Its simple like a hammer, and useful like a ... yeah, like a hammer. :D

So use it, hopefully it will be part of official ansible release (along with mysql_replication) but until that, you can download it from my github. Just place it under library/databases and you can start using it.