Saltstack Loops with multiple Commands


Saltstack still remains my daily system administration tool and the range of uses keeps growing! Today I needed to run multiple commands to toggle options in a Plesk Onyx System Notification page, the check boxes have ID values and there were 4 columns of them.

There was no single command to set all of them to OFF, so I needed to iterate through the ID’s, clear them and then set them.

Below is the script showing a way to run multiple commands in a loop using the same loop ID value. This part just turns OFF all the notifications.

{% for ID in [‘1′,’2′,’3′,’6′,’7′,’12’,’13’,’16’,’18’,’20’,’22’,’23’,’24’,’25’,’26’] %}
admin_{{ ID }}:
cmd.run:
– name: plesk bin notification -u -id {{ ID }} -send2admin false
reseller_{{ ID }}:
cmd.run:
– name: plesk bin notification -u -id {{ ID }} -send2reseller false
client_{{ ID }}:
cmd.run:
– name: plesk bin notification -u -id {{ ID }} -send2client false
email_{{ ID }}:
cmd.run:
– name: plesk bin notification -u -id {{ ID }} -send2email false
{% endfor %}

Enjoy!