1. 程式人生 > >Linux saltstack常用模組

Linux saltstack常用模組

所有模組

  salt '172.30.100.126' sys.list_modules  #列出當前版本支援的模組

  salt '*' sys.doc cp  #顯示指定模組的文件

archive模組

  實現系統層面的壓縮包呼叫,支援gzip、gunzip、rar、tar、unrar、unzip等

cmd模組

  實現遠端的命令列呼叫執行

salt '*' cmd.run 'df -h'
# 執行傳遞的命令,並將結果作為字串返回
salt '*' cmd.script salt://tmp/test.sh
# 從master端下載指令碼,並在本地執行

cp模組

  實現遠端檔案、目錄的複製,以及下載URL檔案等操作

salt '*' cp.get_dir salt://path/to/dir/ /minion/dest
# 從master遞迴複製指定目錄到minion目錄下
salt '*' cp.get_file salt://path/to/file /minion/file
從master複製單個檔案到minion
salt '*' cp.push /etc/hosts
# 把minion端的檔案推送到master端
# 存放目錄預設在/var/cache/salt/master/minions/minion-id/files
salt '*' cp.push /usr/lib/mysql
# 從minion端推送一個目錄到master端

cron模組

  實現被控主機的crontab操作

salt '*' cron.raw_cron root
# 返回指定使用者的cron內容
salt '*' cron.set_job root '*' '*' '*' '*' 1 /usr/local/weekly
# 為指定使用者新增一條cron任務
salt '*' cron.rm_job root /usr/local/weekly
# 為指定使用者刪除一條cron任務

file模組

salt '*' file.chown /etc/passwd root root
# 修改檔案的屬主屬組
salt '*' file.copy /path/to/src /path/to/dst
salt '*' file.copy /path/to/src_dir /path/to/dst_dir recurse=True remove_existing=True
# 從src複製檔案或目錄到dst,可以遞迴複製,可以存在刪除
salt '*' file.move /path/to/src /path/to/dst
# 移動指定檔案或目錄
salt '*' file.rename /path/to/src /path/to/dst
# 修改指定檔案或目錄的名稱
salt '*' file.file_exists /etc/hosts
salt '*' file.directory_exists /etc
# 檢查指定檔案或目錄是否存在
salt '*' file.stats /etc/hosts
# 返回指定檔案或目錄的stats資訊
salt '*' file.mkdir /tmp/test
# 不存在則建立,確保目錄存在
salt '*' file.remove /tmp/foo
# 刪除指定檔案,如果是目錄將被遞迴刪除