saltstack jinja for loop in parallel

When we target minions by globbing, or nodegroups, the defined states will be applied to them in parallel. So one way to achieve this is by moving the “reboot minion” functionality into the state file patch-n1.sls itself.

Example /srv/salt/patch-n1.sls file:

# Some tasks to perform patching, just using 'include' for example
# from /srv/salt/patching/os_pkg.sls
include:
- patching.os_pkg

reboot-after-package-update:
  module.run:
  - name: system.reboot

And in orchestrate /srv/salt/orch/patch_all.sls file:

patch-group1:
  salt.state:
  - tgt: group1
  - tgt_type: nodegroup
  - sls:
    - patch-n1

patch-group2:
  salt.state:
  - tgt: group2
  - tgt_type: nodegroup
  - sls:
    - patch-n2

When we run the orchestration, the each minion will run patching and reboot in parallel.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top