States is a configuration language in Saltstack and requires a large number of states files to be written in daily configuration management. For example, install a package, then manage a configuration file, and finally ensure that a service runs correctly.
Write some states SLS files (files describing the state configuration) to describe and implement our functionality. The states SLS file is written in Yaml syntax. Of course states SLS files also support the use of the Python language, in fact, writing states SLS files is not difficult, the official provides a large number of examples, we just need to remember to write the format, and then according to their actual needs to write the appropriate states SLS file for their own business
View all States lists
Salt ' minion1 ' sys.list_state_modules
Minion1:
-ACL
-Alias
-Alternatives
-Apache
-Archive
-Artifactory
-At
-Blockdev
-Buildout
-Cloud
-cmd
-composer
-Cron
-Disk
-Environ
-Event
-File
-Gem
-Gnomedesktop
-Grafana
-Grains
-Group
-Hipchat
-Host
-HTTP
-Incron
-INI
-Iptables
-JBOSS7
-Kmod
-Libvirt
-Locale
-LVM
-Lvs_server
-Lvs_service
-LXC
-MODJK
-Modjk_worker
-Module
-Mongodb_database
-Mount
-Network
-Openstack_config
-Pagerduty
-Pip
-Pkg
-Pkgng
-Pkgrepo
-PowerPath
-Pyenv
-Quota
-raid
-Rbenv
-Redis
-RVM
-Salt
-Schedule
-Serverdensity_device
-Service
-Slack
-SMTP
-Ssh_auth
-Ssh_known_hosts
-Stateconf
-Status
-Supervisord
-Sysctl
-Syslog_ng
-Test
-TimeZone
-TLS
-Tomcat
-User
-Vbox_guest
-Virtualenv
-Webutil
-Winrepo
View all function of the specified states
View all function of file.states
Salt ' minion1 ' sys.list_state_functions file
Minion1:
-File.absent
-file.accumulated
-File.append
-File.blockreplace
-File.comment
-File.Copy
-File.directory
-File.exists
-File.managed
-File.missing
-File.mknod
-File.mod_run_check_cmd
-File.patch
-File.prepend
-File.recurse
-File.rename
-File.replace
-File.serialize
-File.symlink
-File.touch
-File.uncomment
View specified states specified function usage
To view detailed usage and examples of file.managed states
Salt ' minion1 ' Sys.state_doc file.managed
----------------------------------------------------------------------------------
Let's use a simple example to understand states, and through examples we can see some of the processes and uses of States
Writing a Top.sls file (not required)
Writing States.sls files
In large-scale configuration management work, you need to write a large number of STATES.SLS files. Top.sls is the entry file for the states system, which is responsible for developing which devices call which States.sls files in a large-scale configuration management effort.
We maintain a set of LNMP architecture, we write a lot of States.sls files, it is necessary to deploy the entire LNMP environment in one click, it is necessary to States.sls Top.sls portal file to specify which STATES.SLS files are referenced by the Web machine and DB machine respectively.
Let's start with a new One.sls states file in states's working directory (the base environment defaults to/srv/salt)
Vim/srv/salt/one.sls
/tmp/foo.conf: #id
File.managed: Managed function of the #使用file states
-Source:salt://foo.conf #文件来源 (salt://represents states's working directory)
-User:root #文件属主
-Group:root #文件属组
-mode:644 #文件权限
-Backup:minion #备份原文件
This is a simple file management States.sls file, we can see the method described above file.managed more parameters, the function of this States.sls file is to achieve Minion/tmp/ foo.conf file for unified management, below we can create a new foo.conf file under the states working directory, and then configure the deployment for Minion:
echo "Saltstack Books" >/src/salt/foo.conf
Salt ' * ' State.sls one
Minion1:
----------
ID:/tmp/foo.conf
Function:file.managed
Result:true
Comment:file/tmp/foo.conf is in the correct state
started:14:43:01.568340
duration:12.401 ms
Changes:
Summary
------------
Succeeded:1
failed:0
------------
Total states Run:1
Minion2:
----------
ID:/tmp/foo.conf
Function:file.managed
Result:true
comment:file/tmp/foo.conf Updated
started:00:43:33.336318
duration:109.696 ms
Changes:
----------
Diff:
New file
Mode
0644
Summary
------------
Succeeded:1 (changed=1)
failed:0
------------
Total states Run:1
This completes the simple file management of the Minion machine. Let's introduce a simple configuration management for multiple machines using the TOP.SLS portal file
------------------------------------------------------------------------------------
Create a new Top.sls file in states's working directory first
Vim/srv/salt/top.sls
Base
‘*‘:
-One
' Minion1 ':
-Double
' Minion2 ':
-Three
Then we set up three states file One.sls,two.sls,three.sls, and finally we use the State.highstate command to synchronize simultaneously
Salt ' * ' state.highstate
This article from "Eight Miles" blog, declined reprint!
Saltstack Study Notes 7-states