Create an sls fileIn the same directory as the top file, create a filenamed webserver.sls, containing the following:
1
2
3
apache: # ID declaration
pkg: # state declaration
- installed # function declaration
The first line, called the ID declaration, is an arbitrary identifier.In this case it defines the name of the package to be installed.
The second line, called the State declaration, defines which of the SaltStates we are using. In this example, we are using the pkg state to ensure that a given package is installed.
Then only place state trees in the dev, qa, and prod environments, leavingthe base environment open for generic file transfers. Then the top.sls filewould look something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
dev:
'webserver*dev*':
- webserver
'db*dev*':
- db
qa:
'webserver*qa*':
- webserver
'db*qa*':
- db
prod:
'webserver*prod*':
- webserver
'db*prod*':
- db
Other Ways of Targeting MinionsHere is a slightly more complex top file example, showing the different typesof matches you can perform:
'nag1* or G@role:monitoring':
- match: compound
- nagios.server
In this example top.sls, all minions get the ldap-client, networking, andsalt.minion states. Any minion with an id matching the salt-master* globwill get the salt.master state. Any minion with ids matching the regularexpression ^(memcache|web).(qa|prod).loc$ will get the nagios.mon.web andapache.server states. All Ubuntu minions will receive the repos.ubuntu state,while all RHEL and CentOS minions will receive the repos.epel state. Theminions foo, bar, and baz will receive the database state. Anyminion(奴才) with a pillar named somekey, having a value of abc will receivethe xyz state. Finally, minions with ids matching the nag1* glob(一滴) or with agrain named role equal to monitoring will receive the nagios.serverstate. http://docs.saltstack.cn/zh_CN/l ... top.html#states-top