SaltStack: schedule highstate in batch

saltstack

I would like to schedule a highstate to run every night but not in parallel. Is there a way to add batch option to the scheduling system?

Example:

schedule:
  highstate:
    enabled: True
    function: state.highstate
    maxrunning: 1
    when: 3:00am
    kwargs:
      batch: 1

Ideally I would like to also randomize the time when it runs. I guess I could schedule to run every two hours within one hour time range so it will run only once:

schedule:
  highstate:
    enabled: True
    function: state.highstate
    maxrunning: 1
    range:
      start: 3:00am
      end: 4:00am
    hours: 2
    kwargs:
      batch: 1

Best Answer

When initiating a highstate from the master you can utilize a feature known as batch mode.

The --batch-size flag allows you to specify how many minions to run against in parallel. You can use the command below:

salt --batch-size 1 '*' state.highstate

Regarding the time when it runs, you can use splay argument like the following:

splay:
  start: 10
  end: 15

This will splay the time between 10 and 15 seconds

If you want to use it with a scheduling system:

Edit /etc/anacrontab and add RANDOM DELAY and START_HOURS_RANGE parameters:

# The maximal random delay added to the base delay of the jobs
RANDOM_DELAY=60
# interval, when scheduled jobs can be run, in hours
START_HOURS_RANGE=3-4

1 10 update.daily /usr/bin/salt --batch-size 1 '*' state.highstate

Related Topic