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.
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
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
Edit the
/opt/salt-cookbook/staging/user/init.sls
file to have the following contents:{% if grains['server_type'] == 'app...