mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
Provide the list of files that were included by include_vars
include_vars will now also return a key 'ansible_included_var_files' which contains the list of files that were successfully loaded. This is useful information and, amongst other things, a way for users to know exactly what files were included when debugging their playbooks. This also allows us to improve the integration tests around include_vars.
This commit is contained in:
parent
44bef1dc6b
commit
9fdd07fba8
3 changed files with 40 additions and 7 deletions
|
@ -120,3 +120,17 @@ EXAMPLES = """
|
|||
ignore_files: 'bastion.yml'
|
||||
extensions: ['yml']
|
||||
"""
|
||||
|
||||
RETURN = '''
|
||||
ansible_facts:
|
||||
description: Variables that were included and their values
|
||||
returned: success
|
||||
type: dict
|
||||
sample: {'variable': 'value'}
|
||||
ansible_included_var_files:
|
||||
description: A list of files that were successfully included
|
||||
returned: success
|
||||
type: list
|
||||
sample: [ '/path/to/file.yml', '/path/to/file.json' ]
|
||||
version_added: 2.4
|
||||
'''
|
||||
|
|
|
@ -84,6 +84,7 @@ class ActionModule(ActionBase):
|
|||
task_vars = dict()
|
||||
|
||||
self.show_content = True
|
||||
self.included_files = []
|
||||
|
||||
# Validate arguments
|
||||
dirs = 0
|
||||
|
@ -141,6 +142,7 @@ class ActionModule(ActionBase):
|
|||
result['failed'] = failed
|
||||
result['message'] = err_msg
|
||||
|
||||
result['ansible_included_var_files'] = self.included_files
|
||||
result['ansible_facts'] = results
|
||||
result['_ansible_no_log'] = not self.show_content
|
||||
|
||||
|
@ -237,6 +239,7 @@ class ActionModule(ActionBase):
|
|||
failed = True
|
||||
err_msg = ('{0} must be stored as a dictionary/hash' .format(filename))
|
||||
else:
|
||||
self.included_files.append(filename)
|
||||
results.update(data)
|
||||
|
||||
return failed, err_msg, results
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue