六、saltstack的module组件

时间:2021-04-25 21:25:35

Module是saltstack日常使用中用的最多的一个组件。用于管理操作对象。

查看系统module:

[root@super65 ~]# salt 'super66' sys.list_modules
super66:
- acl
- aliases
- alternatives
- apache

.........

查看module的function:

[root@super65 ~]# salt 'super66' sys.list_functions cmd
super66:
- cmd.exec_code
- cmd.exec_code_all
- cmd.has_exec
- cmd.retcode
- cmd.run
..........

查看function的用法:

[root@super65 ~]# salt 'super66' sys.doc cmd

[root@super65 ~]# salt 'super66' sys.doc cmd.run

使用cmd.run远程执行命令:

[root@super65 ~]# salt 'super66' cmd.run "ifconfig eth0"
super66:
    eth0 Link encap:Ethernet HWaddr 00:0C:29:3E:34:32
    inet addr:192.168.1.66 Bcast:192.168.1.255 Mask:255.255.255.0
    inet6 addr: fe80::20c:29ff:fe3e:3432/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:26347 errors:0 dropped:0 overruns:0 frame:0
    TX packets:11997 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:29597859 (28.2 MiB) TX bytes:1138554 (1.0 MiB)