I'm using a reactor that's triggered whenever a minion is restarted. The reactor then completes 2 steps:
The issue I have is when enforcing the minion configuration if there are changes the minions are restarted causing the reactor to trigger for a second time. Is there a way to set the reactor to run only once while still enforcing the minion configuration?
This is my code:
reactor:
# call orchestrator & pass minion_id
call_orchestrator:
runner.state.orchestrate:
- args:
- mods: orch.salt_orchestrator
- pillar:
value: {{ data["id"] }}
# enforce config:
set_minion_conf:
local.state.apply:
- tgt: {{ data['id'] }}
- arg:
- salt_minion
orchestrator:
call_runner:
salt.runner:
- name: test_runner.up
- arg:
- grains: {{ minion_id }}
master:
reactor:
- 'salt/minion/*/start':
- /srv/salt/react/test.sls
This, would be a good use of grains.
your orchestration would add a grain at the beginning to the minion. then at the end would remove the grain. the orchestration would have to make sure that the minion was restarted with proper use of salt.wait_for_event
please note for salt.wait_for_event
to work the orchestration needs to be sitting and already at the salt.wait_for_event point before the event fires. if the event happens before the orchestration is at the point it will not see the event and will end up timing out. and most likely not do anything that happens after that state. normally this is handled by not waiting for the item to return. such as using cmd.run
with bg: true
to restart the minion so that the restart event isn't waiting for a response which will never come.
to make sure the reactor knows what to do, the minion should first be setup with start_event_grains
set to true
. so the start event includes the grains data in the event. then the reactor would look at the event data look at the grains determine if the grain was set in the grains data in the start event. if it is it just doesn't do anything. if it isn't fire the reactor.