I don't get "watch vs onchanges":
https://docs.saltstack.com/en/latest/ref/states/requisites.html#watch
Note: If a state should only execute when another state has changes, and otherwise do nothing, the new onchanges requisite should be used instead of watch. watch is designed to add additional behavior when there are changes, but otherwise execute normally.
It would be great, if you could add a simple example for both use cases.
My use case: I want to restart service core if a state plugin-foo changed. But service core does not know state plugin-foo.
Thank you.
I think it would be great to have a section showing examples particularly to show the differences between the two requisites.
When you state "But service core does not know state plugin-foo". Can you clarify what you mean by it does not know about the state plugin-foo? If plugin-foo is in another sls file you could include that for the requisites to take effect.
I'm not sure whether the documentation has changed recently, but there are examples of each
at https://docs.saltstack.com/en/latest/ref/states/requisites.html#watch which starts: "A good example of using watch is with a service.running state...."
and at https://docs.saltstack.com/en/latest/ref/states/requisites.html#onchanges where it starts:
"The correct usage would be:"
But, to summarise:
onchanges... state only runs at all if some other state changes
watch... state runs regardless, but additional behvaiours are also run if some other state changes
For your use case then, onchanges simply will not work - you need to use watch.
@RobotLimeLtd thank your for your summary:
onchanges... state only runs at all if some other state changes
watch... state runs regardless, but additional behvaiours are also run if some other state changes
I understood above lines immediately.
The note-box in the docs ("Note: If a state should only execute when ...") says the same but with more word. I suggest to use your summary instead of "If a state should only execute when ...".
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
Most helpful comment
I'm not sure whether the documentation has changed recently, but there are examples of each
at https://docs.saltstack.com/en/latest/ref/states/requisites.html#watch which starts: "A good example of using watch is with a service.running state...."
and at https://docs.saltstack.com/en/latest/ref/states/requisites.html#onchanges where it starts:
"The correct usage would be:"
But, to summarise:
onchanges... state only runs at all if some other state changes
watch... state runs regardless, but additional behvaiours are also run if some other state changes
For your use case then, onchanges simply will not work - you need to use watch.