From b5817802837e2d208aa78bcb65057e2abb2f37a0 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 17 Aug 2016 15:45:31 -0400 Subject: [PATCH 1/2] dont do it --- docsite/rst/developing_modules.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docsite/rst/developing_modules.rst b/docsite/rst/developing_modules.rst index aafe4a4c09d..09084669543 100644 --- a/docsite/rst/developing_modules.rst +++ b/docsite/rst/developing_modules.rst @@ -355,6 +355,13 @@ how the command module is implemented. If a module returns stderr or otherwise fails to produce valid JSON, the actual output will still be shown in Ansible, but the command will not succeed. +Don't write to files directly, use a temporary file and then use the `atomic_move` function from `ansibile.module_utils.basic` to move into place. +This prevents data corruption and ensures keeping the correct context for the file. + +Avoid createng a module that does the work of other modules, this is what Plays and Roles are for, modules should be the building blocks. This leads to code duplication and divergence, making things less uniform, unpredictable and harder to maintain. + +Avoid creating 'caches', Ansible is designed w/o a central server or authority, you cannot guarantee it will not run with different permissions, options or locations. If you need a central authority, have it on top of Ansible (bastion servier, config server, tower, etc), do not try to build it into modules. + Always use the hacking/test-module script when developing modules and it will warn you about these kind of things. From dac5af63cb263ab08a2643da244c5c685cc5c6b9 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 17 Aug 2016 15:49:40 -0400 Subject: [PATCH 2/2] corrected typo, expanded server types --- docsite/rst/developing_modules.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docsite/rst/developing_modules.rst b/docsite/rst/developing_modules.rst index 09084669543..35d1606e7f7 100644 --- a/docsite/rst/developing_modules.rst +++ b/docsite/rst/developing_modules.rst @@ -360,7 +360,7 @@ This prevents data corruption and ensures keeping the correct context for the fi Avoid createng a module that does the work of other modules, this is what Plays and Roles are for, modules should be the building blocks. This leads to code duplication and divergence, making things less uniform, unpredictable and harder to maintain. -Avoid creating 'caches', Ansible is designed w/o a central server or authority, you cannot guarantee it will not run with different permissions, options or locations. If you need a central authority, have it on top of Ansible (bastion servier, config server, tower, etc), do not try to build it into modules. +Avoid creating 'caches', Ansible is designed w/o a central server or authority, you cannot guarantee it will not run with different permissions, options or locations. If you need a central authority, have it on top of Ansible (bastion/cm/ci server, tower, etc), do not try to build it into modules. Always use the hacking/test-module script when developing modules and it will warn you about these kind of things.