Saltstack的返回(return)
操作前准备:先安装依赖包:MySQL-python
1
# yum install MySQL-python -y
方法一:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
所有Minion端的配置文件/etc/salt/minion在最后增加如下几行:
mysql.host: '10.0.0.7'
mysql.user: 'salt'
mysql.pass: 'salt'
mysql.db: 'salt'
mysql.port: 3306
Use the following mysql database schema(创建数据库):
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;
mysql> grant all on salt.* to salt@'%' identified by 'salt';
salt-minion配置文件添加一下内容到最后:
# vim /etc/salt/minion
mysql.host: '10.0.0.7'
mysql.user: 'salt'
mysql.pass: 'salt'
mysql.db: 'salt'
mysql.port: 3306
# /etc/init.d/salt-minion restart
salt-master执行命令:
# salt '*' test.ping --return mysql
mysql> select * from salt.salt_returns\G
*************************** 1. row ***************************
fun: test.ping
jid: 20151123172044880830
return: true
id: linux-node2.example.com
success: 1
full_ret: {"fun_args": [], "jid": "20151123172044880830", "return": true, "retcode": 0, "success": true, "fun": "test.ping", "id": "linux-node2.example.com"}
alter_time: 2015-11-23 17:20:45
1 row in set (0.00 sec)
第二种方法:
1
2
3
4
5
6
7
8
9
10
# vim /etc/salt/master
return: mysql
mysql.host: '10.0.0.7'
mysql.user: 'salt'
mysql.pass: 'salt'
mysql.db: 'salt'
mysql.port: 3306
# salt '*' test.ping #无需加--return mysql
PS:Minion端的错误日志路径如下:
# tail -f /var/log/salt/minion #log文件
页:
[1]