One, Returnner introduction
1, by default, the execution result of the command sent to Minion is returned to Salt-master. The Saltstack Returnner interface allows the results to be sent to any system.
Github:https://github.com/saltstack/salt/tree/develop/salt/returners
Official website: https://docs.saltstack.com/en/latest/ref/returners/
Second, Returnner module list
Three, case
1,returnner Back to Syslog
Salt-master Execute Command:
[[Email protected] ~] # Salt ' * ' test.ping--return syslog DNS02: TRUEDNS01: True
View Salt-minion-side syslog logs
[[Email protected] ~]#tail-f/var/log/messagesDec 9 22:22:31 dns02 python2.6: {"Fun_args": [],"Jid":"20171209222231433150","return": true,"Retcode": 0,"Success": true," Fun":"test.ping","ID":"DNS02"}
2,returnner back to MySQL (single-sided mode)
- Install MySQL (can also be on other servers in master)
[[Email protected] ~] # Yum install–y MySQL
[[email protected] tmp] # service MySQL start Starting MySQL ... success!
[[email protected] tmp] # mysqladmin-u root password ' 123456 '
- Create a database and authorize
--Create a databaseCREATE DATABASE' Salt 'DEFAULT CHARACTER SETUtf8DEFAULTCOLLATE utf8_general_ci; Use' salt ';DROP TABLE IF EXISTS' Jids ';CREATE TABLE' jids ' (' Jid ' )varchar(255) not NULL,`Load' Mediumtext not NULL,UNIQUE KEY' Jid ' (' Jid ')) ENGINE=InnoDBDEFAULTCHARSET=UTF8;DROP TABLE IF EXISTS' Salt_returns ';CREATE TABLE' salt_returns ' (' Fun 'varchar( -) not NULL, ' Jid 'varchar(255) not NULL,`return' Mediumtext not NULL, ' ID 'varchar(255) not NULL, ' success 'varchar(Ten) not NULL, ' Full_ret ' Mediumtext not NULL,KEY' ID ' (' id '),KEY' Jid ' (' Jid '),KEY"Fun" (' Fun ')) ENGINE=InnoDBDEFAULTCHARSET=UTF8;--AuthorizedGRANT All Privileges onSalt.* to 'Salt'@'%'Identified by 'Salt'; FlushPrivileges;
- Modify all Minion configuration files and add them at the end of the configuration file:
[[Email protected] ~] # vi/etc/salt/minion ' 10.80.0.162 ' 'salt' MySQL. Pass ' Salt ' 'salt'3306
- Restart all Minion Services
[[Email protected] ~] # Salt ' * ' Service.restart salt-minion dns01: TRUEDNS02: True
- All Minion Mount Mysql-python modules
[[email protected] tmp]#Salt ' * ' Cmd.run ' yum install-y mysql-python 'dns02:loaded Plugins:fastestmirror, refresh-PackageKit, security Setting up InstallProcessLoading mirror speeds from cached Hostfile*epel:mirrors.tongji.edu.cn Resolving Dependencies-Running Transaction Check---> Package mysql-python.x86_64 0:1.2.3-0.3.c1.1. El6 'll be installed-finished Dependency Resolution Dependencies resolved================================================================================Package Arch Version Repository Size================================================================================Installing:mysql-python x86_64 1.2.3-0.3.C1.1.EL6 Base 86k Transaction Summary================================================================================Install1Package (s) Total Download size:86k installed Size:246k downloading packages:running rpm_check_debug Running Transaction Test Transaction test succeeded Ru Nning Transaction Installing:mysql-python-1.2.3-0.3.c1.1.el6.x86_64 1/1Verifying:mysql-python-1.2.3-0.3.c1.1.el6.x86_64 1/1Installed:mysql-python.x86_64 0:1.2.3-0.3.c1.1. El6 Complete!dns01:loaded Plugins:fastestmirror, refresh-PackageKit, security Setting up InstallProcessLoading mirror speeds from cached Hostfile*epel:mirrors.tongji.edu.cn Resolving Dependencies-Running Transaction Check---> Package mysql-python.x86_64 0:1.2.3-0.3.c1.1. El6 'll be installed-finished Dependency Resolution Dependencies resolved================================================================================Package Arch Version Repository Size================================================================================Installing:mysql-python x86_64 1.2.3-0.3.C1.1.EL6 Base 86k Transaction Summary================================================================================Install1Package (s) Total Download size:86k installed Size:246k downloading packages:running rpm_check_debug Running Transaction Test Transaction test succeeded Ru Nning Transaction Installing:mysql-python-1.2.3-0.3.c1.1.el6.x86_64 1/1Verifying:mysql-python-1.2.3-0.3.c1.1.el6.x86_64 1/1Installed:mysql-python.x86_64 0:1.2.3-0.3.c1.1. El6 Complete!
[[email protected] tmp] # Salt ' * ' cmd.run ' hostname '--return mysql DNS02: dns02dns01: dns01
Mysql> Select * fromSalt_returns;+---------+----------------------+---------+-------+---------+------------------------------------------------ ----------------------------------------------------------------------------------------------+|Fun|Jid| return |Id|Success|Full_ret|+---------+----------------------+---------+-------+---------+------------------------------------------------ ----------------------------------------------------------------------------------------------+|Cmd.run| 20171210074613759042 |"Dns02"|Dns02| 1 |{"Fun_args":["hostname"], "Jid": "20171210074613759042", "return":" Dns02 "," Retcode ":0, "Success": true, "fun": "Cmd.run", "id": "DNS02"}||Cmd.run| 20171210074613759042 |"Dns01"|Dns01| 1 |{"Fun_args":["hostname"], "Jid": "20171210074613759042", "return":" Dns01 "," Retcode ":0, "Success": true, "fun": "Cmd.run", "id": "dns01"}|+---------+----------------------+---------+-------+---------+------------------------------------------------ ----------------------------------------------------------------------------------------------+2Rowsinch Set(0.00Sec
Snailshadow Tags: returnner,saltstack
Saltstack Learning -2:returnner-Send results to Syslog and MySQL (single-sided mode)