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

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
主站蜘蛛池模板: 闽清县| 望奎县| 英超| 天祝| 亳州市| 安国市| 武威市| 靖州| 汕尾市| 大渡口区| 文山县| 溧水县| 滁州市| 和平县| 静宁县| 罗定市| 黑山县| 湘潭市| 昌都县| 达孜县| 江川县| 佛山市| 南阳市| 晋州市| 石河子市| 辽中县| 西乡县| 绥江县| 永善县| 山东省| 延寿县| 弋阳县| 大荔县| 呼和浩特市| 札达县| 河东区| 玉环县| 四会市| 搜索| 亚东县| 晋中市|