From 7b4ff28b8780bca35669d98b2480e5a549741ddf Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Tue, 23 Jun 2015 14:44:58 -0700 Subject: [PATCH] Creating modules: use if __name__ --- docsite/rst/developing_modules.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docsite/rst/developing_modules.rst b/docsite/rst/developing_modules.rst index 9e784c6418e..f08cda8e68d 100644 --- a/docsite/rst/developing_modules.rst +++ b/docsite/rst/developing_modules.rst @@ -238,7 +238,8 @@ The 'group' and 'user' modules are reasonably non-trivial and showcase what this Key parts include always ending the module file with:: from ansible.module_utils.basic import * - main() + if __name__ == '__main__': + main() And instantiating the module class like:: @@ -483,6 +484,12 @@ Module checklist * The return structure should be consistent, even if NA/None are used for keys normally returned under other options. * Are module actions idempotent? If not document in the descriptions or the notes * Import module snippets `from ansible.module_utils.basic import *` at the bottom, conserves line numbers for debugging. +* Call your :func:`main` from a condtional so that it would be possible to + test them in the future example:: + + if __name__ == '__main__': + main() + * Try to normalize parameters with other modules, you can have aliases for when user is more familiar with underlying API name for the option * Being pep8 compliant is nice, but not a requirement. Specifically, the 80 column limit now hinders readability more that it improves it * Avoid '`action`/`command`', they are imperative and not declarative, there are other ways to express the same thing