There are major inconsistencies in how views a Result output vs how one accesses it. For example, running this command
The use of { code} run_command('mkdir ~/boltexamples', $nodes).each | $result | { notice($result) type } {code }
Provides me with a json hash output that looks easy to navigate (after piping through | python -mjson.tool:
{code:json} { "node": "puppet.c.splunk-217321.internal", "object": "mkdir ~/boltexamples", "result": { "exit_code": 0, "stderr": "", "stdout": "" }, "status": "success", " refer to the type ": "command" } {code}
Now looking at this of action that created a result , I would assume I could access the node name, object , result, and status just by referring is unable to be exposed as an attribute on the hash keys, result object since that's what I'm looking at. Assuming I've not yet dove into the docs and I'm just reading existing code and want to poke around, I may go and do this:
{ code} run_command('mkdir ~/boltexamples', $nodes).each | $result | { notice($result['node']) type } {code }
Which is frustrating because the output I get is:
{code} Starting: command 'mkdir ~/boltexamples' on puppet.c.splunk-217321.internal Finished: command 'mkdir ~/boltexamples' with 0 failures used elsewhere in 2 Puppet . 28 sec
Finished Possible solutions : plan firstproject::firstplan in 5.1 sec Plan completed successfully with no result {code}
So I guess that's an empty hash? How do I actually access these variables? Now I have to go to the documentation to see what is what - which explains that I can access those as functions, but function names have no correllation to what I was just looking at, in fact we hide the mapping in the code here:
https://github 1 . com/puppetlabs/bolt/blob/master/lib/bolt/result.rb#L93-L99
Ah, now I see if I want the node name, I have Rename this key to call $result.target.name - otherwise I just get the result of { code} Target('puppet.c.splunk-217321.internal', { "user"=>"cbarker" action } ) {code } Bonus surprise: I'd think I could get away and expose it with `$result a method . type` to see what type of function this was, but instead, I get the ruby definition of the object: 2. Add a { code} Object[ { name => 'Result', attributes => {'value' => Hash[String[1], Data], 'target' => Target to_data } , functions => {'error' => Callable[[0, 0], Optional[Error]], 'message' => Callable[[0, 0], Optional[String]], 'ok' => Callable[[0, 0], Boolean], '[]' => Callable[[String[1]], Data] } }] {code}
Making the onscreen output of Bolt be logically consistent with methods method to call and extract the Result object that data will be essential for new users to learn how to access and work with it. If we're going to to have `notice($result)` output returns a hash , I should be able equivalent to access the subhash without having to read the docs json output . So far I have yet to be able to access This will make the equivalent of `$result["object"]` or `$result["type"]` even though that would be usecase which triggered the logical way I could access it while looking at initial ticket, the output of the code. I can't tell if it is just undocumented or a bug or a mixture of both.
Edit: ability to clarify, I don't know how to get pass the contents of object or type at all from this result , can't seem from one action directly to find an example of how I could load it in a plan anywhere, regardless of invocation method task easier . This may or may not include renaming type. |
|
|