https://docs.saltstack.com/en/latest/topics/yaml/index.htmlYAML: three board axe 1. Indent: 2 spaces, cannot use Tab 2. Colon: key: value note that there are spaces 3. Short horizontal line: - list1 please note that there are spaces - list2 3. Configuration management path assignment
3.1. master specifies the basic path of configuration management
[root@salt100 salt]# pwd /etc/salt [root@salt100 salt]# vim master .................. # Example: # file_roots: # base: # - /srv/salt/ # dev: # - /srv/salt/dev/services # - /srv/salt/dev/states # prod: # - /srv/salt/prod/services # - /srv/salt/prod/states # # Just release the following comment # It's also possible not to change the configuration, because it's a default configuration file_roots: base: - /srv/salt .................. [root@salt100 salt]# systemctl restart salt-master.service # The configuration file has been modified and the service must be restarted
3.2. Create corresponding directory
[root@salt100 ~]# mkdir -p /srv/salt4. Test case - single state management
4.1. Write test case - install apache
1. Specify a specific directory for later maintenance[root@salt100 salt]# pwd /srv/salt [root@salt100 salt]# mkdir web [root@salt100 salt]# cd web/ [root@salt100 web]# pwd /srv/salt/web2. Write sls file
[root@salt100 web]# pwd /srv/salt/web [root@salt100 web]# cat apache.sls # Suffix sls, sls file will be found when salt is executed # sls files allow comments to exist, and the content can be copied and used directly # A custom ID, unique ID apache-install: # pkg is an execution module. Refer to the method of using installed pkg.installed: # -names parameter supports multiple lists - names: - httpd - httpd-devel # enable: True means: power on and start automatically apache-service: service.running: - name: httpd - enable: True
4.2. Execute on the master machine salt100
Deploy and install httpd for salt01, salt02 and salt03# Operation on the master machine [root@salt100 ~]# salt 'salt0*' test.ping # See if salt01, salt02 and salt03 can communicate salt01: True salt03: True salt02: True [root@salt100 ~]# salt 'salt0*' state.sls web.apache # Deploy httpd to salt01, salt02 and salt03 # Explain: # 1. The basic directory of master configuration management is / srv/salt # 2. The path of apache.sls is / srv/salt/web/apache.sls # 3. state.sls web.apache describes the state module and calls the SLS method. The file called is the apache.sls file under the web path [only the last SLS suffix is omitted]Note: what has been done
1. Send / srv/salt/web/apache.sls file from master to minion;
2. After minion gets the file, execute the contents of apache.sls according to the master instruction
# View at minion end [root@salt01 salt]# pwd /var/cache/salt [root@salt01 salt]# ll total 0 drwxr-xr-x 6 root root 103 Dec 11 23:52 minion [root@salt01 salt]# tree . └── minion ├── accumulator ├── extmods ├── files │ └── base │ └── web │ └── apache.sls ├── highstate.cache.p ├── proc └── sls.p 7 directories, 3 files
4.3. Explanation of execution result information
# Execution return result is unordered [root@salt100 ~]# salt 'salt0*' state.sls web.apache salt02: # salt02 execution result information ---------- ID: apache-install # Self defined ID in apache.sls [name] Function: pkg.installed Name: httpd Result: True Comment: The following packages were installed/updated: httpd Started: 23:51:46.604986 Duration: 30335.469 ms Changes: ---------- httpd: ---------- new: 2.4.6-88.el7.centos old: httpd-tools: ---------- new: 2.4.6-88.el7.centos old: mailcap: ---------- new: 2.1.41-2.el7 old: ---------- ID: apache-install Function: pkg.installed Name: httpd-devel Result: True Comment: The following packages were installed/updated: httpd-devel Started: 23:52:16.965844 Duration: 6661.51 ms Changes: ---------- apr-devel: ---------- new: 1.4.8-3.el7_4.1 old: apr-util-devel: ---------- new: 1.5.2-6.el7 old: cyrus-sasl: ---------- new: 2.1.26-23.el7 old: cyrus-sasl-devel: ---------- new: 2.1.26-23.el7 old: expat-devel: ---------- new: 2.1.0-10.el7_3 old: httpd-devel: ---------- new: 2.4.6-88.el7.centos old: libdb-devel: ---------- new: 5.3.21-24.el7 old: openldap: ---------- new: 2.4.44-20.el7 old: 2.4.44-13.el7 openldap-devel: ---------- new: 2.4.44-20.el7 old: ---------- ID: apache-service Function: service.running Name: httpd Result: True Comment: Service httpd has been enabled, and is running Started: 23:52:24.619598 Duration: 314.737 ms Changes: ---------- httpd: True Summary for salt02 ------------ Succeeded: 3 (changed=3) Failed: 0 ------------ Total states run: 3 Total run time: 37.312 s salt01: # salt01 execution result information .................. salt03: # salt03 execution result information ---------- ..................5. Salt advanced status management Precautions for use in production environment: 1. '*' cannot be used during execution. All minion s cannot be executed 2. It can't be executed directly, test=True first;
5.1. Location and name of advanced status sls file
Location of the default file "roots"
You do not need to modify the configuration file. It is OK by default.
5.2. Write top.sls file
[root@salt100 salt]# pwd /srv/salt [root@salt100 salt]# tree . ├── top.sls └── web └── apache.sls 1 directory, 2 files [root@salt100 salt]# cat top.sls base: # Use Wildcards 'salt0*': - web.apache # - web.nginx # There can be multiple # Specify specific minion 'salt03': - web.apache
5.3. Execute advanced status
[root@salt100 ~]# salt 'salt01' state.highstate test=True # You have to do this first .................. # Reason: prevent yourself from manually changing the configuration information of components on the minion machine, but not synchronizing to salt; # As a result, it was directly implemented and then changed back. [root@salt100 ~]# salt 'salt01' state.highstate # Perform advanced status, and search through top.sls ..................