SaltStack practice: Remote execution-Returners,
Remote Execution of SaltStack-Returners
@ (Learning) [SaltStack]
Remote Execution of SaltStack-Returners
Returners list introduction mysql returner usage 1 install pip and MySQLdb2 configure mysql database 2 configure salt-master3 Test
1. Returners list
Returners |
Description |
Carbon_return |
Take data from salt and "return" it into a carbon else er |
Cassandra_cql_return |
Return data to a cassandra server |
Cassandra_return |
Return data to a Cassandra ColumnFamily |
Couchbase_return |
Simple returner for Couchbase. |
Couchdb_return |
S imple returner for CouchDB. |
Django_return |
A returner that will infor a Django system that returns are available using Django's signal system. |
Elasticsearch_return |
Return data to an elasticsearch server for indexing. |
Etcd_return |
Return data to an etcd server or cluster |
Hipchat_return |
Return salt data via hipchat. |
Influxdb_return |
Return data to an influxdb server. |
Kafka_return |
Return data to a Kafka topic |
Local |
The local returner is used to test the returner interface, it just prints |
Local_cache |
Return data to local job cache |
Memcache_return |
Return data to a memcache server |
Mongo_future_return |
Return data to a mongodb server |
Pai_return |
Return data to a mongodb server |
Multi_returner |
Read/Write multiple returners |
Mysql |
Return data to a mysql server |
Nagios_return |
Return salt data to Nagios |
Odbc |
Return data to an ODBC compliant server. |
Pgjsonb |
Return data to a PostgreSQL server with json data stored in Pg's jsonb data type |
Postgres |
Return data to a postgresql server |
Postgres_local_cache |
Use a postgresql server for the master job cache. |
Pushover_returner |
Return salt data via pushover (http://www.pushover.net) |
Rawfile_json |
Take data from salt and "return" it into a raw file containing the json, with one line per event. |
Redis_return |
Return data to a redis server |
Sentry_return |
Salt returner that reports execution results back to sentry. |
Slack_returner |
Return salt data via slack |
Sms_return |
Return data by SMS. |
Smtp_return |
Return salt data via email |
Splunk |
Send json response data to Splunk via the HTTP Event Collector |
Sqlite3_return |
Insert minion return data into a sqlite3 database |
Syslog_return |
Return data to the host operating system's syslog facility |
Xmpp_return |
Return salt data via xmpp |
Zabbix_return |
Return salt data to Zabbix |
2. Introduce mysql returner usage
Mysql returner requires the python MySQLdb module, so you need to install the MySQLdb module first.
2.1 install pip and MySQLdb
[root@salt-master111 tmp]# yum -y install python-devel mysql-devel[root@salt-master111 tmp]# unzip setuptools-36.0.1.zip[root@salt-master111 tmp]# cd setuptools-36.0.1[root@salt-master111 tmp]# python setup.py install[root@salt-master111 tmp]# cd ../[root@salt-master111 tmp]# tar -zxvf pip-9.0.1.tar.gz [root@salt-master111 tmp]# cd pip-9.0.1[root@salt-master111 tmp]# python setup.py install[root@salt-master111 tmp]# pip install mysql[root@salt-master111 tmp]# pythonPython 2.7.5 (default, Nov 6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import MySQLdb>>>
2.2 configure the mysql database
Use the official data table structure and grant permissions to the minion server.
CREATE DATABASE `salt` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;USE `salt`;---- Table structure for table `jids`--DROP TABLE IF EXISTS `jids`;CREATE TABLE `jids` ( `jid` varchar(255) NOT NULL, `load` mediumtext NOT NULL, UNIQUE KEY `jid` (`jid`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;CREATE INDEX jid ON jids(jid) USING BTREE;---- Table structure for table `salt_returns`--DROP TABLE IF EXISTS `salt_returns`;CREATE TABLE `salt_returns` ( `fun` varchar(50) NOT NULL, `jid` varchar(255) NOT NULL, `return` mediumtext NOT NULL, `id` varchar(255) NOT NULL, `success` varchar(10) NOT NULL, `full_ret` mediumtext NOT NULL, `alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, KEY `id` (`id`), KEY `jid` (`jid`), KEY `fun` (`fun`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;---- Table structure for table `salt_events`--DROP TABLE IF EXISTS `salt_events`;CREATE TABLE `salt_events` (`id` BIGINT NOT NULL AUTO_INCREMENT,`tag` varchar(255) NOT NULL,`data` mediumtext NOT NULL,`alter_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,`master_id` varchar(255) NOT NULL,PRIMARY KEY (`id`),KEY `tag` (`tag`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;grant all on salt.* to salt@"10.1.0.%" identified by "saltpass";
2.2 configure salt-master
/Etc/salt/master
return: mysqlmysql.host: 'salt-host'mysql.user: 'salt'mysql.pass: 'saltpass'mysql.db: 'salt'
Restart master and minion services
systemctl restart salt-mastersystemctl restart salt-minion
2.3 Test
Run commands on the master.
[root@salt-master111 ~]# salt 'salt-master111' test.ping --return mysqlsalt-master111: True[root@salt-master111 ~]#
Check whether data is in salt_returns in the database.
mysql> select * from salt_returns;+-----------+----------------------+--------+----------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------+---------------------+| fun | jid | return | id | success | full_ret | alter_time |+-----------+----------------------+--------+----------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------+---------------------+| test.ping | 20170609172835506510 | true | salt-master111 | 1 | {"fun_args": [], "jid": "20170609172835506510", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "salt-master111"} | 2017-06-09 17:28:35 || test.ping | 20170609172841714924 | true | salt-master111 | 1 | {"fun_args": [], "jid": "20170609172841714924", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "salt-master111"} | 2017-06-09 17:28:41 || test.ping | 20170609173636297217 | true | salt-master111 | 1 | {"fun_args": [], "jid": "20170609173636297217", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "salt-master111"} | 2017-06-09 17:36:36 || test.ping | 20170609173653113715 | true | salt-master111 | 1 | {"fun_args": [], "jid": "20170609173653113715", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "salt-master111"} | 2017-06-09 17:36:53 |+-----------+----------------------+--------+----------------+---------+--------------------------------------------------------------------------------------------------------------------------------------------+---------------------+4 rows in set (0.00 sec)