在cmdmod模塊中cmd.run、cmd.run_all、cmd.run_stdout等均可以執行shell命令,要靜止某些shell命令,能夠修改_run()這個函數來完全的靜止調用這個命令。python
centos 7:/usr/lib/python2.7/site-packages/salt/modules/cmdmod.py
文件第235行shell
centos 6:/usr/lib/python2.6/site-packages/salt/modules/cmdmod.py
文件第235行centos
例如rm命令:python2.7
''' Do the DRY thing and only call subprocess.Popen() once ''' #禁止rm命令 if r'rm ' in cmd: ret = {} ret['stdout'] = "'rm' is dangerous!!! MISSION FAILED!!!" ret['stderr'] = '' ret['pid'] = '' ret['retcode'] = 0 return ret
if _is_valid_shell(shell) is False:函數
.......
若是是修改_run()函數後就不用修改run()等其它函數了,修改文件後重啓minion後生效,測試下效果。測試
[root@perf023 master.d]# salt '10.159.59.10' cmd.run "rm -f /tmp/123.log" 10.159.59.10: 'rm' is dangerous!!! MISSION FAILED!!! [root@perf023 master.d]#