From a252d71573ca7adaae1b0a5a9c915e398242007d Mon Sep 17 00:00:00 2001 From: Erwan Velu Date: Fri, 2 Dec 2016 09:34:27 +0100 Subject: [PATCH] Update developing_modules.rst (#18646) I was wondering how to return a new fact from a module I got the answer on IRC thx to "mgedmin". I read this doc several time but didn't understood that I had to return a "ansible_facts" in the module.exit_json. This change is about showing a sample code of it to help the next reader ;) --- docsite/rst/dev_guide/developing_modules.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docsite/rst/dev_guide/developing_modules.rst b/docsite/rst/dev_guide/developing_modules.rst index 7fa928e287..c7f37a70b2 100644 --- a/docsite/rst/dev_guide/developing_modules.rst +++ b/docsite/rst/dev_guide/developing_modules.rst @@ -246,6 +246,10 @@ this, just have the module return a `ansible_facts` key, like so, along with oth These 'facts' will be available to all statements called after that module (but not before) in the playbook. A good idea might be to make a module called 'site_facts' and always call it at the top of each playbook, though we're always open to improving the selection of core facts in Ansible as well. + +Returning a new fact from a python module could be done like:: + + module.exit_json(msg=message, ansible_facts=dict(leptons=5000, colors=my_colors)) .. _common_module_boilerplate: