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

Using conditionals in states and pillars

One of the best advantages of any programming language or configuration tool is its ability to make decisions based on various properties, and apply configurations, or perform tasks, based on these decisions. In this recipe, you will learn how to leverage the decision-making ability of Salt and use it to your advantage.

How to do it...

We will use the same minion as the previous recipe for this task:

  1. Add a custom grain to the minion with the server_type key and value as app:
    server_type: app
  2. In the staging environment, create two pillars named groups and users. Also, create two states named group and user. Add them to top.sls for both states and pillars to be available to all nodes.
  3. Edit /opt/salt-cookbook/pillar/staging/user/init.sls to have the following content:
    users:
      {% if grains['server_type'] == 'app' %}
      stg_user: stg-app
      {% elif grains['server_type'] == 'db' %}
      stg_user: stg-db
      {% endif %}
      stg_user_passwd...
lock icon The rest of the chapter is locked
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