Problem:
I found stat module and I was wondering what I could use from the JSON 
output for my conditional statement.
I either have to use  debug: msg="{{stat_output}}"  or refer to the code: 
https://github.com/ansible/ansible/blob/devel/library/files/stat#L100

The stat module is pretty neat and compact but other modules aren't. They 
are usually long and contains multiple nested if/else.

But basically most people will be looking for module.exit_json for the 
success case.

I propose to begin the effort to document the JSON output.

1. But before we do that, what are people's opinion on this?
2. Should we add the JSON manually to DOCUMENTATION, or should there be a 
mechanism to automate this? 

By automation, there are two ways:

- write a test for each module, run it, pulls the output and add to the 
documentation
But this approach has two drawbacks. One modules such as ec2 cannot be run 
without an ec2 instance, and two
people who wish to build ansible documentation locally may not be willing 
to run the tests.


The second method is to define the structure of the success JSON output at 
the beginning of the function call.
This way we should be able to QUICKLY pull out the dictionary using the ast 
module.

But this has two drawback. 
1) We will not know whether the user wrote stat or foobar when they call 
module.exist_json(changed=True, stat=stat_dict).
2) We MAY want to cover fail_json as well, but the keys are not fixed 
either. For example, the followings are extracted
from the file module:
     module.fail_json(path=path, msg='Error while replacing: %s' % str(e))
    module.fail_json(dest=path, src=src, msg='Cannot link, %s exists at 
destination' % prev_state)

I guess we are down to manually adding the JSON output?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/bcd26114-f79d-4438-ba3a-a2949772f172%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to