Salt Basic Configuration Management

Source: Internet
Author: User

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,

    1. SOURCE specifies the path of the file to be copied on master, where salt://is relative to the salt root directory
    2. Name specifies the path to copy to the Minion
    3. user specifies that all users of the file group specify the file's owning users
    4. 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.

  1. . SLS This file is not allowed to be waived (i.e. Webserver.sls from webserver)

  2. It's a good choice to use subdirectories to organize.
    1. Each subdirectory describes a resource

    2. Pip.dev used to denote sub-directories pip/dev.sls

  3. Init.sls represents a boot file in a subdirectory, which means the subdirectory itself, so ' pip/init.sls ' means ' pip '.

  4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.