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

Get Salt Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.