March 2019
Intermediate to advanced
412 pages
9h 49m
English
Similar to data returned as part of a module exit, a module can directly create facts for a host by returning data in a key named ansible_facts. Providing facts directly from a module eliminates the need to register the return of a task with a subsequent set_fact task. To demonstrate this usage, let's modify our module to return the source and dest data as facts. Because these facts will become top-level host variables, we'll want to use more descriptive fact names than source and dest – replace the current module.exit_json line in our module with the code listed:
facts = {'rc_source': module.params['source'],
'rc_dest': module.params['dest']}
module.exit_json(changed=True, ansible_facts=facts)
We'll also add a task ...
Read now
Unlock full access