Search icon CANCEL
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

Configuring the Salt environment and pillar paths

In this recipe, we are going to configure the environment and pillar paths for Salt to use when we mention environments while performing Salt operations. Ideally, any infrastructure should have environments for development, testing, QA, production, and so on, for isolation of respective code and a seamless workflow. Salt enables us to implement this in a few simple steps by providing options to define environments for states and pillars.

How to do it...

In the primary configuration /etc/salt/master file, we will configure the section called file_roots. Under this parameter option, we will name each environment we want to configure and the path of the directory that will contain the configuration files for that environment.

  1. Let's create the directories we want to use as the environment paths and then configure four environments named base, production, staging, and development as follows:
    [root@salt-master ~]# mkdir –p \
    /opt/salt-cookbook/{base,production,staging,development}
    
  2. Edit /etc/salt/master to have following content:
    file_roots:
      base:
        - /opt/salt-cookbook/base
      production:
        - /opt/salt-cookbook/production
      staging:
        - /opt/salt-cookbook/staging
      development:
        - /opt/salt-cookbook/development
  3. Next, we will create the directories we want to use as pillar paths and configure them following the same environment conventions as follows:
    [root@salt-master ~]# mkdir –p \
    /opt/salt- cookbook/pillar/{base,production,staging,development}
    
  4. Edit /etc/salt/master to have following content:
    pillar_roots:
      base:
        - /opt/salt-cookbook/pillar/base
      production:
        - /opt/salt-cookbook/pillar/production
      staging:
        - /opt/salt-cookbook/pillar/staging
      development:
        - /opt/salt-cookbook/pillar/development
  5. We now restart the salt-master daemon for these changes to take effect:
    [root@salt-master ~]# service salt-master restart
    

How it works...

Environments in Salt are designed to keep the configuration files for each environment isolated into respective containers for different stages of deployment such as development, QA, staging, and production. Ideally, the configurations can be written in either of the environments such as staging, and after a proper test phases, they can be migrated to the production environment.

Here, we opted for the /opt/salt-cookbook path to be the base directory of all our configurations. Next, we have chosen four environments for our infrastructure, namely, base, staging, production, and development. The base environment is the default in Salt and the path /srv/salt is taken as the base directory for all configurations if not configured explicitly as we have done earlier.

We then created the directory paths we want to use as the environment paths and mentioned them under the file_roots parameter, specifying the environment name and the path that points the configuration files for that environment:

file_roots:
  <environment_name>:
    - <environment_directory_path>

Pillars are one of the best features of Salt, which enable us to isolate data that needs to be kept secure such as keys and passwords. Next, we have chosen the /opt/salt-cookbook/pillar path to be our base directory for all pillar data and created directories for each environment that will contain pillar data, which is usable in that environment only.

We then edited the Salt master configuration file to include the environment names and their paths under the pillar_roots section for Salt to identify them as the pillar configuration paths:

pillar_roots:
  <environment_name>:
    - <pillar_directory_path>

Finally, we restarted the Salt master daemon for the changes to take effect.

It is also to be noted that when executing the salt command, the environment has to be mentioned for the minion(s). This is generally done with the saltenv option on the command line. However, this parameter can also be specified in the minion configuration /etc/salt/minion file, as follows:

environment: production

If this parameter is not set, the base environment is taken as the default environment.

See also

  • The Using pillar data in states and Writing and retrieving pillar data recipes in Chapter 2, Writing Advanced Salt Configurations, to learn more about how to use pillars in states
  • The Understanding and configuring Salt pillars recipe, for detailed examples of pillar configurations
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