Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Salt Cookbook

You're reading from   Salt Cookbook Over 80 hands-on recipes to efficiently configure and manage your infrastructure with Salt

Arrow left icon
Product type Paperback
Published in Jul 2015
Publisher
ISBN-13 9781784399740
Length 350 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Anirban Saha Anirban Saha
Author Profile Icon Anirban Saha
Anirban Saha
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Salt Architecture and Components FREE CHAPTER 2. Writing Advanced Salt Configurations 3. Modules, Orchestration, and Scaling Salt 4. General Administration Tasks 5. Advanced Administration Tasks 6. Managing Application Servers 7. Managing Databases 8. Configuring Salt Cloud 9. Managing Amazon Web Services 10. Salt Event and Reactor System 11. Troubleshooting Index

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
You have been reading a chapter from
Salt Cookbook
Published in: Jul 2015
Publisher:
ISBN-13: 9781784399740
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime