4

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
Law29
  • 3,557
  • 1
  • 16
  • 28
HTF
  • 3,148
  • 14
  • 52
  • 82

1 Answers1

3

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

Alaa Chatti
  • 406
  • 2
  • 6
  • Thanks for your reply but this doesn't solve my problem. I'm aware about batch mode but my question is how to use it with scheduling system. Splay only works with time intervals (minutes, hours etc.) but my requirement is so it runs between specified time range (3am-4am, day 1: 3:15am, day 2: 3:25am etc.). – HTF Jan 04 '16 at 10:59
  • I edited my answer, check it out – Alaa Chatti Jan 04 '16 at 13:23
  • I ment [SaltStack scheduling system] [1] but thanks for alternative solution.[1]: https://docs.saltstack.com/en/latest/topics/jobs/#scheduling-jobs – HTF Jan 05 '16 at 08:04
  • Yes I see what you mean but what you need can't be done using salt stack scheduling system. Feel free to validate my answer :-) – Alaa Chatti Jan 05 '16 at 09:47