O'Reilly logo

Salt Cookbook by Anirban Saha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required