saltstack其他运行模式

除了常规的运行模式外,salt还有几种运行模式

salt-call --local可以直接在minion上自执行,多用于本机自测试,此方式几乎不用,知道即可

1 [root@linux-node2 ~]# salt-call --local test.ping
2 local:
3     True

很明显,因为是本机自测试,所以只有自己的返回值

salt-ssh是一种不需要在安装minion即可对各目标机器进行操作的方式,熟悉ansible的同学们是不是眼前一亮呢~没错,我萌的salt可以直接指定ansible的文件然后对各个机器直接进行控制,当然这种方法也不常用。除了命令变为salt-ssh外,后面的一切与salt正常使用无区别

 1 [root@linux-node1 ~]# yum install salt-ssh -y
 2 [root@linux-node1 salt]# cat /etc/salt/roster             # 这里是定义被连接主机的文件
 3 # Sample salt-ssh config file
 4 #web1:
 5 #  host: 192.168.42.1 # The IP addr or DNS hostname
 6 #  user: fred         # Remote executions will be executed as user fred
 7 #  passwd: foobarbaz  # The password to use for login, if omitted, keys are used
 8 #  sudo: True         # Whether to sudo to root, not enabled by default
 9 #web2:
10 #  host: 192.168.42.2
11 linux-node2.example.com:
12   host: 192.168.56.12
13   user: root
14   passwd: redhat
15   port: 22
16 [root@linux-node1 salt]# salt-ssh '*' cmd.run 'whoami'
17 linux-node2.example.com:
18     root
19 [root@linux-node1 salt]# cat /etc/salt/myroster             # 创建一个自己定义的roster文件
20 linux-node2.example.com:
21   host: 192.168.56.12
22   user: root
23   passwd: redhat
24   port: 22
25 [root@linux-node1 salt]# salt-ssh --roster-file=/etc/salt/myroster '*' cmd.run 'whoami'
26 linux-node2.example.com:
27     root
28 [root@linux-node1 salt]# salt-ssh --roster=ansible --roster-file=ansible-file-path '*' cmd.run 'whoami'                # 使用ansible存货单来进行操作,我没有ansible不执行了

salt-run是指认master去完成工作的方式。正常的流程为master发布任务minion匹配到然后拿到任务自己去执行,将执行结果扔回队列master再去读取结果,以test.ping为例就是各个minion自己执行了test.ping了自己,然后返回结果。而salt-run则是由master亲自去一个个ping各个minion

1 [root@linux-node1 salt]# salt-run manage.up            # 命令不太一样
2 - linux-node1.example.com
3 - linux-node2.example.com
原文地址:https://www.cnblogs.com/bfmq/p/8030495.html