I think I got this. My main issue was the 'true' logic with an 'onlyif', because that's always only going to either run (= and therefore meet the requirement) or not run at all (= which also meets the requirement since it's not a failure).
I feel the choice of words here leaves room for confusion. Like "unless"... unless succeeds? unless fails? "requires" also leaves some amgiuity as well, since it considers the requirement met as long as the required resource did not explicitly return a failure. So "notrun" is just as good as success, which to me doesn't really intuitively match what I think "require" means.
Like any other resource,
Exec
s model target-machine state, though in their case, that state is local to the context of one catalog run. Often it is described as whether theExec
's command has been run or not, but it is better characterized the other way around, as whether theExec
's command needs to be run or not. If it is in the "needs to be run" state then successfully executing theExec
's command transitions it to the "does not need to be run" state.
The
unless
,onlyif
, andcreates
properties of anExec
serve to determine the initial state of the corresponding physical (so to speak) resource. If none of them are provided then the physical resource is initially in the "needs to be run" state. If one or more of them is provided then they may indicate that theExec
initially is in the "does not need to be run" state. And that's the target state. In that case, then, theExec
is successfully applied without running its command.
This has been a point of confusion with the Exec resource type for the whole nine-ish years that I have been involved with Puppet. Maybe it's time to actually file an issue against the docs to get it cleaned up.
Got it, thanks everyone.
Just one small point to add - I'm not actually directly concerned with Execs here. If you look at my original example, I was needing to do a conditional check like "if directory exists then...", and my Exec-based solution for it is just an ugly workaround. I understand the puppet philosophy here is focused on being declarative, but it's just extremely common that we don't have the pleasure of working in a purely declarative environment. As such I think it'd be nice to see unless/requires/etc evolve further.