-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
puppet.run always returns 0 #20850
Comments
@br0ch0n, what is the output of |
and a node:
Running salt '*' cmd.run_all 'puppet agent -t' returns what I'd expect is correct behavior, i.e. a non-zero retcode on a puppet change:
As for passing the
Don't know if that's significant or not. What does seem important tho, is that cmd.run_all 'puppet agent -t 'seems good yet puppet.run (which basically just wraps the former) is not. So somehow the proper retcode is getting obscured away even though it's out there. |
A return code of 2 from the puppet agent actually isn't an error. It just tells us that it succesfully applied one or more changes. What happens if the agent returns 4 or 6? |
I'd suggest adding "detailed-exitcodes" to the arguments for the puppet agent here:
or (even better) simply change the whole list to just contain 'test', which implies all the other entries + --detailed-exitcodes, according to puppet agent --help:
With this in place, the agent returns 0 or 2 for success, everything else is failure. |
@dhs-rec, do you think you could submit a pull request against the 2014.7 branch to fix this? |
Ah, this makes a bit more sense now. I should've looked closer at the code. The comments say that we're running 'puppet agent --test' but in actuality, the actual arguments implied by --test are being explicitly called instead (but no detailed-exitcodes, which I could've sworn was default anyway, but I guess not). |
Possible fix for 'puppet.run always returns 0 #20850'
If I'm reading this right, won't this change still obscure the exit code to either 0 or 1? It would be desirable to return the actual puppet agent code since one might want to see if anything changed during the run. It should be left up to the caller to interpret the exit codes IMO. |
Yes. Thought about this, too. However, I wasn't sure whether an exit code of 2 would make the caller think there was an error, so I combined the "good" cases into one exit code (0). Feel free to change that. |
Have created #22446 for the above |
Issue #20850 puppet run should return actual code
@br0ch0n, you're right, what I did was wrong. Wasn't aware that it actually returns a dict which contains the return code in a field "retcode". However, the code as it is now still treats 2 as failure, which is wrong. 2 means "Puppet agent has successfully applied some changes". 0 means "Agent had nothing to do". All other return codes indicate failure. Have created #22526 which does it better. |
@dhs-rec Thanks, but I don't understand what you mean by the code treating the return value as a failure? Salt isn't doing any interpretation of the return value one way or another. It just sends pid/retcode/stderr/stdout back to the caller, who can interpret it as needed. @rallytime I don't know that I'd consider this resolved since we don't seem to have an agreement on desired behavior. |
@br0ch0n: If I run "salt myminion state.highstate", and one of the states is
with a puppet agent returning 2, I get something like this (relevant output only):
So yes, the returncode IS actually interpreted by salt. And it gets it wrong. Returncode 2 doesn't indicate failure. Reg my pull request: No, it does not just revert your previous commit. The code is different. It takes into account that cmd.run returns a dict, which my previous commit (the one you reverted) did not. I agree that the detailed exit codes provide useful information, but they also lead to false negatives. Maybe a proper way to fix this would be to allow cmd.run to accept a list of "good" exit codes, like Puppet's exec resources do. But as long as it doesn't do that, the next best thing IMHO is simply not to fail on those good cases. |
Return codes are problematic as a nonzero value can vary widely among all the utilities that salt interacts with. There is an open issue, #18510, to address this in a standard way. |
Sorry for not commenting on this for awhile. Per @dhs-rec 's use case, I agree that it's best to stick to the lowest common denominator and not fail on nonzero. In my use case, i.e. using just the puppet module (salt '*' puppet.run) directly rather than calling the module from a state, no interpretation takes place, but I see that that doesn't cover all cases. So, I guess we should just close this but with the caveat that a better solution should be found once there is progress on #18510 . In the meantime, I'll just have to use cmd.run if I want to get detailed exit info from puppet runs. |
Thanks for the update @br0ch0n. |
puppet.run, which seems to by default call "puppet agent -t" using cmd.run_all isn't returning the proper exit code but seems to always return 0:
local run:
salt run:
The text was updated successfully, but these errors were encountered: