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.
- But before we do that, what are people’s opinion on this?
- 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.
- We will not know whether the user wrote stat or foobar when they call module.exist_json(changed=True, stat=stat_dict).
- 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?