一、在master 的file_root目錄/srv/salt下編輯top.sls:python
base: '*': - pip
二、在/srv/salt目錄下建立pip目錄,編輯init.sls文件:web
這裏是複製get-pip.py文件:函數
pip: file.managed: - source: salt://get-pip.py - name: /home/cheeron/get-pip.py - user: cheeron - group: cheeron - mode: 644
這裏的pip定義,使用了file.managed函數,ui
3. 而後就能夠經過命令 salt ‘*’ state.highstate 執行文件複製任務spa
執行過程:code
test1: ---------- ID: pip Function: file.managed Name: /home/cheeron/get-pip.py Result: True Comment: File /home/cheeron/get-pip.py is in the correct state Started: 14:44:18.203548 Duration: 36.115 ms Changes: Summary ------------ Succeeded: 1 Failed: 0 ------------ Total states run: 1 test2: ---------- ID: pip Function: file.managed Name: /home/cheeron/get-pip.py Result: True Comment: File /home/cheeron/get-pip.py updated Started: 18:14:04.441644 Duration: 5567.605 ms Changes: ---------- diff: New file group: cheeron mode: 0644 user: cheeron Summary ------------ Succeeded: 1 (changed=1) Failed: 0 ------------ Total states run: 1
若是get-pip.py文件有變化,那麼在執行state.highstate命令時對經過diff對比是哪裏有改動。server
.sls 這個文件是被放棄的不被容許的 (i.e. webserver.sls 來源於 webserver)blog
每一個子目錄描述一個資源ip
pip.dev 用來表示子目錄 pip/dev.sls資源
init.sls 在一個子目錄裏面表示引導文件,也就表示子目錄自己, 因此``pip/init.sls`` 就是表示``pip``.
若是同時存在``pip.sls`` 和 pip/init.sls,則 pip/init.sls 被過濾,pip.sls``將被用來表示pip.
複製文件而且執行,經過cmd.run實現:
pip: file.managed: - source: salt://get-pip.py - name: /home/cheeron/get-pip.py - user: cheeron - group: cheeron - mode: 644 cmd.run: - name: python /home/cheeron/get-pip.py - require: - file: /home/cheeron/get-pip.py
這樣,在執行了複製命令以後就會執行python /home/cheeron/get-pip.py