官术网_书友最值得收藏!

  • Salt Cookbook
  • Anirban Saha
  • 510字
  • 2021-07-16 13:21:55

Understanding and writing the top file

In this recipe, we will understand and learn how to write the top file, the file which determines how the states are applied to the nodes or minions in Salt. We will apply the state that we configured in the previous recipe to minions.

How to do it...

The state configured in the previous recipe will now be applied to minions in the development environment.

  1. Create a file named top.sls in the base directory of the development environment:
    [root@salt-master ~]# touch \
    /opt/salt-cookbook/development/top.sls
    
  2. Edit the /opt/salt-cookbook/development/top.sls file and add the following contents:
    development:
      '*':
        - user
      'salt-minion':
        - match: list
        - hostconfig

How it works...

The top.sls file in Salt determines which state will be applied to which minions. It has an extension of .sls similar to all other files in Salt. It is written in the YAML format and takes minion matchers in the form of wildcards, nodegroups, lists, grains, and so on. We will look at all of the ways to match minions throughout the book when we go through each of these components.

First, we created the top.sls file in the base directory of the development environment, that is, /opt/salt-cookbook/development, and then we populated it with the required definitions.

The first line indicates the environment we are configuring the top file for, that is, development. Without this, the base environment will be used as default. The next line indicates a wildcard * meaning that it will match all minions and apply the listed state to all of them. Then, we listed the user state that we already configured:

development:
  '*':
    - user

We can also match minions when applying states in the top.sls file in the following manner:

development:
  '*':
    - user
  'salt-minion':
    - match: list
    - hostconfig

Here, we see a second block of node definition and state that introduces a new key called match. Instead of the wildcard in the preceding block, this block has the name of a minion node called salt-minion, which is the hostname of the minion node that will synchronize with the master and the second line in the block:

- match: list

This line indicates that the type of minion parameter to match is a list, which is nothing but the hostname of the minion. The line that has the name of the minion can be a comma-separated line of multiple hostnames:

'webserver,dbserver,appserver,proxyserver'

The list matcher will match the line as a list of minion names. Then, we mentioned a state called hostconfig, which is also the name of a state not configured in the book so far. This example means that the hostconfig state will be applied to all the minions in the list, which in this case is the minion named salt-minion.

There's more…

In Salt, minions can be matched in more ways than shown in this recipe, such as nodegroups, grains, IP/subnets, and so on. We will learn how to apply them in Chapter 3, Modules, Orchestration, and Scaling Salt.

See also

  • The Installing and configuring the Salt minion recipe, to learn how to install and configure minions
主站蜘蛛池模板: 张家港市| 石首市| 田东县| 吉林省| 平安县| 子长县| 泸西县| 阿城市| 凤阳县| 镇江市| 宣城市| 十堰市| 泸溪县| 宣城市| 调兵山市| 隆化县| 互助| 澄城县| 屏山县| 潜山县| 松滋市| 罗源县| 东丽区| 青川县| 呼玛县| 浪卡子县| 西林县| 新绛县| 泽库县| 牡丹江市| 绵阳市| 微山县| 安多县| 怀宁县| 西充县| 炎陵县| 巴青县| 曲沃县| 樟树市| 平南县| 马山县|