salt默认模块路径
[root@node1 base]# ll /usr/lib/python2.6/site-packages/salt/modules/saltstack
自定义salt模块
[root@node1 _grains]# cd /srv/salt/base/[root@node1 base]# mkdir _modules[root@node1 base]# cd _modules/[root@node1 base]# salt '*' cmd.run 'df -h' #将这个命令写成模块 [root@node1 _modules]# cat my_disk.pydef list(): cmd = 'df -h' ret = __salt__['cmd.run'](cmd) return ret
将模块发到minion
[root@node1 _modules]# salt '*' saltutil.sync_modulesnode2: - modules.my_disknode1: - modules.my_disk
执行模块
[root@node1 _modules]# salt '*' my_disk.listnode2: Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 8.3G 2.6G 5.3G 34% / tmpfs 495M 12K 495M 1% /dev/shm /dev/sda1 477M 28M 424M 7% /bootnode1: Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 8.3G 2.7G 5.3G 34% / tmpfs 495M 16K 495M 1% /dev/shm /dev/sda1 477M 28M 424M 7% /boot