Salt ' * ' saltutil.refresh_pillar
The official website example really did not understand, the English dish. In fact, a simple step.
Reference documents
Https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.mysql.html
https://z900collector.wordpress.com/linux/using-the-saltstack-mysql-module/
Salt-master is mainly looking for/usr/lib/python2.6/site-packages/salt/modules/test.py.
[Email protected] salt]# cat/etc/salt/minion
master:172.1.1.1
Id:cm1
Mysql.host: ' localhost '
mysql.port:3306
Mysql.user: ' Root '
Mysql.socket: ' X.sock '
Mysql.pass: ' xx '
Mysql.charset: ' UTF8 '
/etc/init.d/salt-minion restart
‘‘‘
Execution order, test command
State.show_sls execute function to see the order of salt State execution
sudo salt stage-db1 state.show_sls mysql
sudo salt stage-db1 state.apply mysql test=true
sudo salt stage-db1 state.apply mysql
Mysql
sudo salt stage-db1 mysql.db_list
‘‘‘
Salt ' * ' mysql.db_list
The most complete example
Https://www.digitalocean.com/community/tutorials/saltstack-infrastructure-creating-salt-states-for-mysql-database-servers
1.salt-minion End
MySQL connection information/etc/salt/minion.d/mysql.conf
mysql.default_file: '/etc/mysql/salt.cnf'
Vim/etc/mysql/salt.cnf
Mysql.host: ' localhost '
mysql.port:3306
Mysql.user: ' Root '
Mysql.socket: ' X.sock '
Mysql.pass: ' xx '
Mysql.charset: ' UTF8 '
2.vim/srv/pillar/top.sls
Base
'[email protected]:d EV and [email protected]:d bserver':
-Match:compound
-Dev.mysql
' [Email protected]:stage and [email protected]:d bserver ':
-Match:compound
-Stage.mysql
' [email protected]:p rod and [email protected]:d bserver ':
-Match:compound
-Prod.mysql
3.vim/srv/salt/mysql/init.sls
Debconf-utils:
Pkg.installed
Mysql_setup:
Debconf.set:
-Name:mysql-server
-Data:
' Mysql-server/root_password ': {' type ': ' Password ', ' value ': ' {{salt[' pillar.get '] (' MYSQL:ROOT_PW ', ')}} '}
' Mysql-server/root_password_again ': {' type ': ' Password ', ' value ': ' {{salt[' pillar.get '] (' MYSQL:ROOT_PW ', ')}} '}
-Require:
-Pkg:debconf-utils
PYTHON-MYSQLDB:
Pkg.installed
Mysql-server:
Pkg.installed:
-Require:
-Debconf:mysql-server
-Pkg:python-mysqldb
Mysql:
Service.running:
-Watch:
-Pkg:mysql-server
-File:/etc/mysql/my.cnf
Mysql:
Service.running:
-Watch:
-Pkg:mysql-server
-File:/etc/mysql/my.cnf
/ETC/MYSQL/MY.CNF:
File.managed:
- Source:salt://mysql/files/etc/mysql/my.cnf.jinja
-Template:jinja
-User:root
-Group:root
-mode:640
-Require:
-Pkg:mysql-server
/etc/salt/minion.d/mysql.conf:
File.managed:
-Source: salt://mysql/files/etc/salt/minion.d/mysql.conf
-User:root
-Group:root
-mode:640
-Require:
-Service:mysql
/ETC/MYSQL/SALT.CNF:
File.managed:
- Source:salt://mysql/files/etc/mysql/salt.cnf.jinja
-Template:jinja
-User:root
-Group:root
-mode:640
-Require:
-Service:mysql
Restart_minion_for_mysql:
Service.running:
-Name:salt-minion
-Watch:
-File:/etc/salt/minion.d/mysql.conf
Above is an example on the Digitoean cloud. The most important thing is /ETC/SALT/MINION.D .
This article from "Want to have a dream, in case the realization of" blog, declined reprint!
Saltstack–using the Mysql Module