How to configure scheduling from the salt pillar data

Without crashing the minion

Prerequisites:

  • Have a salt master and a salt minion configured

Introduction

Automated updates of your VM’s are a blessing. You can schedule them from your salt master from within the pillar data

Create a schedule in pillar

  1. Create a dir and file
mkdir /srv/pillar/schedule
touch /srv/pillar/schedule/update.sls
  1. Place the following file in update.sls:
schedule:
  update:
    maxrunning: 1
    run_on_start: False
    function: state.apply
    args:
      - 'base.updates'
    when:
      - Wednesday 13:30
  1. Add the following to your top.sls (within the pillar data): (you can either choose to target one minion, a group or everything except)
base:
  'hades*':
    - schedule.update
  1. Refresh the pillar data salt '*' saltutil.refresh_pillar

Create a state to update in salt

  1. Create a dir and a file
mkdir /srv/salt/base/updates/
touch /sr/v/salt/base/updates/init.sls
  1. Add a function to this state to update all packages including the minion: It is dan with a cmd.run because the salt-minion might stop working when it’s updating
updates:
  cmd.run:
    - name: echo salt-call --local pkg.upgrade refresh=true | at now + 1 minute
    - order: last

Optional 3. In the top sls add this new state so it can also be applied when performing a highstate on a minion.

base:
   'hades':
      - base.updates

Testing whether the schedule is active on the minion:

  1. Using pillar.get to get the schedule data on a specific minion:
salt 'hades*' pillar.get schedule
hades.localdomain.local:
    ----------
    update:
        ----------
        _continue:
            True
        _next_fire_time:
            None
        _splay:
            None
        args:
            - base.updates
        function:
            state.apply
        maxrunning:
            1
        name:
            update
        run_on_start:
            False
        when:
            - Wednesday 13:30

or you can use pillar.item schedule:

salt 'hades*' pillar.item schedule
hades.localdomain.local:
    ----------
    schedule:
        ----------
        update:
            ----------
            _continue:
                True
            _next_fire_time:
                None
            _splay:
                None
            args:
                - base.updates
            function:
                state.apply
            maxrunning:
                1
            name:
                update
            run_on_start:
                False
            when:
                - Wednesday 13:30

or schedule.list:

salt 'hades*' schedule.list
hades.localdomain.local:
    schedule:
      update:
        args:
        - base.updates
        enabled: true
        function: state.apply
        maxrunning: 1
        name: update
        run_on_start: false
        when:
        - Wednesday 13:30

Please note: make sure package at is installed on your minion(s)

Used documentation: