Book Image

Salt Cookbook

By : Anirban Saha
Book Image

Salt Cookbook

By: Anirban Saha

Overview of this book

Table of Contents (18 chapters)
Salt Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Setting and using variables in states


Variables are one of the most important features of any language or tool used to set user-defined data and manipulate it as and when required. In this recipe, you will learn how to set variables in Salt states and use the variables to do some advanced task.

How to do it...

  1. Configure a minion in the staging environment and create a pillar and state with the name user. In the minion, configure the following grain:

    server_type: db
  2. Edit the /opt/salt-cookbook/pillar/staging/user/init.sls file to have the following contents:

    app_user_list:
      optimus:
        uid: 7001
        passwd: $1$Cf1V2QaF$.qyeAQ34CLqyvEnes7/VH1
      bumblebee:
        uid: 7002
        passwd: $1$KvbpASt.$L97XRqLVc0OaspatEE/n4/
    
    db_user_list:
      megatron:
        uid: 7001
        passwd: $1$8J9bAeG6$HMMV.EoMycJyLL.pb6kHj0
      cyclonus:
        uid: 7002
        passwd: $1$2HqtGifG$MF3WHFSOmKG4gksHOVvA30
  3. Edit the /opt/salt-cookbook/staging/user/init.sls file to have the following contents:

    {% if grains['server_type'] == 'app...