Configuration Management in SaltStack practice-State relationship
Configuration Management in SaltStack practice-State relationship
Learning SaltStack
Configuration Management in SaltStack practice-State relationship
1. State-related module
1.1 pkg
1.2 file
1.3 service
1.4 requisites
two。 Practical application
1. State dependent module 1.1 pkg
Status module: pkg
Function: manage package status
Common methods:
Pkg.installed # ensure that the package is installed, or install it if not installed
Pkg.latest # make sure the package is the latest version, if not, upgrade it
Pkg.remove # ensure that the package is uninstalled or, if previously installed, uninstall
Pkg.purge # deletes its configuration file in addition to remove
Official documents:
Https://docs.saltstack.com/en/latest/ref/states/all/salt.states.pkg.html
1.2 file
Status module: file
Function: manage file status
Common methods:
File.managed # ensures that the file exists and is in the corresponding state
File.recurse # ensures that the directory exists and is in the corresponding state
File.absent # make sure the file does not exist and delete it if it does
Official documents:
Https://docs.saltstack.com/en/latest/ref/states/all/salt.states.file.html
1.3 service
Status module: service
Function: manage service status
Common methods:
Service.running # ensure that the service is running and start if it is not running
Service.enabled # ensure that the service boots up automatically
Service.disabled # ensure that the service boot does not start automatically
Service.dead # ensure that the service is not currently running and stop if it is running
Official documents:
Https://docs.saltstack.com/en/latest/ref/states/all/salt.states.service.html
1.4 requisites
Status module: requisites
Function: handle the relationship between states
Common methods:
Require # I rely on a certain state (requirement, need)
Require_in # I am dependent on a certain state (required, needed)
Watch # I follow a certain status (monitoring)
Watch_in # I am followed by a certain status (monitored)
Official documents:
Https://docs.saltstack.com/en/latest/ref/states/requisites.html
two。 Practical application
[root@salt-master112 salt] # cat / srv/salt/dev/lamp.sls
Lamp-pkg-install:
Pkg.installed:
-names:
-php
-php-fpm
-mysql
-php-mysql
-php-pdo
Apache-service:
Pkg.installed:
-name: httpd
File.managed:
-name: / etc/httpd/conf/httpd.conf
-source:
-salt://files/httpd.conf
-user: root
-group: root
-mode: 644
-require:
-pkg: apache-service
Service.running:
-name: httpd
-enable: True
-reload: True
-watch:
-file: apache-service
Mysql-service:
Pkg.installed:
-name: mysql-server
-require_in:
-file: mysql-service
File.managed:
-name: / etc/my.cnf
-source:
-salt://files/my.cnf
-user: root
-group: root
-mode: 644
-watch_in:
-service: mysql-service
Service.running:
-name: mysqld
-enable: True
Php-fpm-service:
Service.running:
-name: php-fpm
-enable: True