{"id":19,"date":"2013-08-13T00:28:05","date_gmt":"2013-08-12T23:28:05","guid":{"rendered":"http:\/\/188.166.119.205\/?p=19"},"modified":"2026-11-10T05:52:05","modified_gmt":"2026-11-10T05:52:05","slug":"mysql-variables-module-for-ansible","status":"publish","type":"post","link":"https:\/\/banyek.net\/?p=19&lang=en","title":{"rendered":"MySQL variables module for ansible"},"content":{"rendered":"<p>I&#8217;ve created and another module for this besides the mysql_replication named mysql_variables.<\/p>\n<p>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.<\/p>\n<p>For example, when you wanna to set read_only mode via shell, you can do that like this:<\/p>\n<p><!--more--><\/p>\n<pre><code>ansible db-secondary.bfc.kinja-ops.com -m shell -a \"mysql -e 'select @@read_only'\"\ndb-secondary.bfc.kinja-ops.com | success | rc=0 &gt;&gt;\n\n[root@admin banyek]# ansible db-secondary.bfc.kinja-ops.com -m shell -a \"mysql -e 'set global read_only=1'\"\ndb-secondary.bfc.kinja-ops.com | success | rc=0 &gt;&gt;\n<\/code><\/pre>\n<p>Not so neat, isn\u2019t it, eh? And I have not spoken about the \u2014user and \u2014password variables, so this could be really annoying.<\/p>\n<p>That\u2019s 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 \u2018ansible like\u2019 with \u2018changed\u2019 tags, and so on. Like this:<\/p>\n<pre><code>[root@admin banyek]# ansible db-secondary.bfc.kinja-ops.com -m mysql_variables -a \"variable=read_only\"\ndb-secondary.bfc.kinja-ops.com | success &gt;&gt; {\n    \"changed\": false,\n    \"msg\": [\n        [\n            \"read_only\",\n            \"OFF\"\n        ]\n    ]\n}\n\n[root@admin banyek]# ansible db-secondary.bfc.kinja-ops.com -m mysql_variables -a \"variable=read_only value=1\"\ndb-secondary.bfc.kinja-ops.com | success &gt;&gt; {\n    \"changed\": true,\n    \"msg\": \"Variable change succeeded\"\n\n}\n<\/code><\/pre>\n<p>That\u2019s it. Its simple like a hammer, and useful like a \u2026 yeah, like a hammer. \ud83d\ude00<\/p>\n<p>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 <a href=\"https:\/\/github.com\/banyek\/ansible\/blob\/mysql_variables\/library\/database\/mysql_variables\">GitHub<\/a>. Just place it under library\/databases and you can start using it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve 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. For example, when you wanna to set read_only mode via [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[134],"tags":[228,144,126,202],"class_list":["post-19","post","type-post","status-publish","format-standard","hentry","category-tech-en","tag-ansible-en","tag-mysql-en","tag-oldblog-en","tag-python-en"],"_links":{"self":[{"href":"https:\/\/banyek.net\/index.php?rest_route=\/wp\/v2\/posts\/19","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/banyek.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/banyek.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/banyek.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/banyek.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19"}],"version-history":[{"count":1,"href":"https:\/\/banyek.net\/index.php?rest_route=\/wp\/v2\/posts\/19\/revisions"}],"predecessor-version":[{"id":445,"href":"https:\/\/banyek.net\/index.php?rest_route=\/wp\/v2\/posts\/19\/revisions\/445"}],"wp:attachment":[{"href":"https:\/\/banyek.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/banyek.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/banyek.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}