Apply states on minions after they come online

saltstack

Imagine you want to apply some states on a group of minions, such as all ubuntu clients. It's possible by the time we apply that states some of the minions are offline.

How long do states remain in the message bus to be pushed on minions? What strategies do you suggest to tackle this problem and change minions states when they come back online? Is there a better way to make minion pull states than running salt-call state.highstate?

Best Answer

Salt comes with the so called reactor system, which should fit your needs.

The following is untested and taken from the linked docs.

/etc/salt/master.d/reactor.conf:

reactor:
    - 'salt/minion/*/start':          # Match the start event
        - /srv/reactor/start.sls      # Things to do when a minion starts

/srv/reactor/start.sls:

highstate_run:
    local.state.apply:
        - tgt: {{ data['id'] }}  # data included event data, id is the minion id.

This should ensure that each minion applies state.highstate after it has opened a connection to the salt master.