execute a copy file using the Salt State
1. Edit Top.sls under Master's File_root directory/srv/salt:
Base: ' * ' : -Pip
2. Create the PIP directory under the/srv/salt directory and edit the Init.sls file:
Here is the copy get-pip.py file:
pip: file.managed: -source:salt://get-pip.py -Name:/home/cheeron/get-pip.py - user:cheeron - group:cheeron -mode:644
Here's the PIP definition, using the file.managed function,
- SOURCE specifies the path of the file to be copied on master, where salt://is relative to the salt root directory
- Name specifies the path to copy to the Minion
- user specifies that all users of the file group specify the file's owning users
- mode specifies that the permission of the file is represented by a number 4 for Read permission 2 for write permission 1 for EXECUTE permission
3. You can then perform a file copy task from the Command Salt ' * ' state.highstate
Execution process:
test1:----------id:pip Function:file.managed Name:/home/cheeron/get-pip.py result:true comment:file/home/cheeron/get-pip.py is inchThe correct state Started:14:44:18.203548Duration:36.115Ms Changes:summary------------succeeded:1failed:0------------total states run:1test2:----------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.441644Duration:5567.605ms changes:----------diff:new file Group:cheeron mode: 0644user:cheeronsummary------------succeeded:1 (changed=1) failed:0------------total states run:1
If the get-pip.py file changes, then the diff is changed when executing the state.highstate command.
. SLS This file is not allowed to be waived (i.e. Webserver.sls from webserver)
-
- It's a good choice to use subdirectories to organize.
-
Each subdirectory describes a resource
Pip.dev used to denote sub-directories pip/dev.sls
Init.sls represents a boot file in a subdirectory, which means the subdirectory itself, so ' pip/init.sls ' means ' pip '.
If both ' Pip.sls ' and Pip/init.slsare present, then Pip/init.sls is filtered andPip.sls ' will be used to represent the pip.
Copying files and executing them, implemented through 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
In this way, the python/home/cheeron/get-pip.py is executed after the copy command is executed
Salt Basic Configuration Management