The need to do the same task repeatedly for a number of entities of the same type is a very basic requirement of any role in an organization. To achieve this, languages and tools provide us with the feature of iterations, simply known as loops. In this recipe, you will learn how to apply iterations in our configuration.
We will use the same minion as the previous recipe. Modify the user pillar, that is,
edit /opt/salt-cookbook/pillar/staging/user/init.sls
to have the following contents:dev_user_list: optimus: uid: 7001 passwd: '$1$Dw1TxMI7$pmeYTdmz.rlunqPd7JELR.' bumblebee: uid: 7002 passwd: '$1$ZHUeIAfq$6sJl9rHVDX2UjBH1KrPZP1' ironhide: uid: 7003 passwd: '$1$rcJAiq7y$bJzv3HzVTbeQlA3cIu1Gb1'
Edit
/opt/salt-cookbook/staging/user/init.sls
to have the following contents:{% for user, details in pillar['dev_user_list'].iteritems() %} {{ user }}: user.present: - home: /home/{{ user }} - uid: {{ details['uid'] }} ...