Idea: error shorthand / making writing modules even simpler

Some modules are getting a bit long because they do a lot of error handling. I’d like to keep this easy so I’ve been thinking about ways to reduce boilerplate without requiring a common ‘support’ library, which would mean software required on
each machine (bad, for our design goals).

While it makes sense to be able to return JSON for complex data structures, often a simple script (or an error scenario), means it complicates the script.

I am thinking that we also allow an additional type of module return, a string, that looks like this:

“ANSIBLE key=value key=value key=value”

This would allow most modules and error handling to return simple things like

print “ANSIBLE failed=1 msg=‘Splines Not Reticulated’”
sys.exit(1)

versus the troublesome boilerplate of:

print json.dumps({
failed = True,
msg = ‘Splines Not Reticulated’
})
sys.exit(1)

The core code (runner) would know how to automatically parse both formats, though this would allow quick scripting in nearly all cases. The non-JSON format just starts with “ANSIBLE”.

The slight downside is modules that do that would lose some type information. We’d have to know to auto-cast “failure” to a boolean, and “rc” to an int. Not too bad!

But we also get to lose most of the JSON import boilerplate, and make much more compelling examples.

Also if I can get “failed” to come from the paramiko exit code (hopefully this is possible), we may be able to do away with needing to return “failed” explicitly too. That would rock.

–Michael