Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions action_plugins/juniper_junos_common_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def run(self, tmp=None, task_vars=None):
self._task.args['_module_utils_path'] = module_utils_path
# Pass the hidden _module_name option
self._task.args['_module_name'] = self._task.action
# Pass the hidden _inventory_hostname option
self._task.args['_inventory_hostname'] = task_vars['inventory_hostname']

# Call the parent action module.
return super(ActionModule, self).run(tmp, task_vars)
10 changes: 6 additions & 4 deletions module_utils/juniper_junos_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,9 @@ class ModuleDocFragment(object):
'_module_name': dict(type='str',
required=True,
default=None),
'_inventory_hostname': dict(type='str',
required=True,
default=None),
}

# Known RPC output formats
Expand Down Expand Up @@ -681,6 +684,7 @@ def __init__(self,
mutually_exclusive=mutually_exclusive,
**kwargs)
self.module_name = self.params.get('_module_name')
self.inventory_hostname = self.params.get('_inventory_hostname')
# Remove any arguments in internal_spec
for arg_name in internal_spec:
self.params.pop(arg_name)
Expand Down Expand Up @@ -1845,8 +1849,7 @@ def save_text_output(self, name, format, text):
file_path = os.path.normpath(self.params.get('diffs_file'))
elif self.params.get('dest_dir') is not None:
dest_dir = self.params.get('dest_dir')
hostname = self.params.get('host')
file_name = '%s.diff' % (hostname)
file_name = '%s.diff' % (self.inventory_hostname,)
file_path = os.path.normpath(os.path.join(dest_dir, file_name))
else:
if self.params.get('dest') is not None:
Expand All @@ -1857,13 +1860,12 @@ def save_text_output(self, name, format, text):
mode = 'ab'
elif self.params.get('dest_dir') is not None:
dest_dir = self.params.get('dest_dir')
hostname = self.params.get('host')
# Substitute underscore for spaces.
name = name.replace(' ', '_')
# Substitute underscore for pipe
name = name.replace('|', '_')
name = '' if name == 'config' else '_' + name
file_name = '%s%s.%s' % (hostname, name, format)
file_name = '%s%s.%s' % (self.inventory_hostname, name, format)
file_path = os.path.normpath(os.path.join(dest_dir, file_name))
if file_path is not None:
try:
Expand Down