I have an Ansible playbook with this task..
---
- name: Set mysql_variable
mysql_variables:
variable: mysql_variable
value: 2000
- name: Reload MySQL
service:
name: mysql
state: restarted
enabled: yes
the 1st task sets the variable to desired state, I can verify.. but it's not persistent. When 2nd task reloads mysql service, the variable gets set to default value.
How to set this variable persistent with Ansible on the target node??
The community.mysql.mysql_variables module supports this with mode: persist
, assuming you have MySQL 8.0+ and are setting a dynamic variable:
- name: Configure a MySQL dynamic setting
community.mysql.mysql_variables:
variable: "binlog_expire_logs_seconds"
value: "{{ '1w' | community.general.to_seconds | int }}"
mode: persist
become: true
The equivalent SET PERSIST
statement:
$ sudo mysql --execute "SET persist binlog_expire_logs_seconds = 604800;"
Show any variables persisted to mysqld-auto.cnf
(reference):
$ sudo mysql --execute "SELECT * FROM performance_schema.persisted_variables;"
+---------------------------------+----------------+
| VARIABLE_NAME | VARIABLE_VALUE |
+---------------------------------+----------------+
| binlog_expire_logs_seconds | 604800 |
| max_allowed_packet | 268435456 |
+---------------------------------+----------------+
MySQL 5.7 doesn't support this statement (and it's EOL).
Some variables still need to be updated in the appropriate my.cnf
or mysqld.cnf
with the lineinfile
module.
Look for errors like:
Variable 'innodb_log_file_size' is a read only variable
Variable 'bind_address' is a read only variable