diff --git a/plugins/action/network_resource.py b/plugins/action/network_resource.py index 4f5e94930..dfcbe129e 100644 --- a/plugins/action/network_resource.py +++ b/plugins/action/network_resource.py @@ -81,23 +81,36 @@ def run(self, task_vars=None): run_mode = self._get_run_mode() + result = {} if run_mode == RunMode.RM_LIST: - return self._list_resource_modules() + result = self._list_resource_modules() elif run_mode in [RunMode.RM_GET, RunMode.RM_CONFIG]: - return self._run_resource_module() + result = self._run_resource_module() + + result.update( + { + "ansible_network_os": self._task_vars.get( + "ansible_network_os" + ), + "ansible_connection": self._task_vars.get( + "ansible_connection" + ), + } + ) + return result def _run_resource_module(self): new_task = self._task.copy() - module = self._get_resource_module() - if not module: + self._module = self._get_resource_module() + if not self._module: msg = "Could not find resource module '%s' for os name '%s'" % ( self._name, self._os_name, ) raise AnsibleActionFail(msg) - new_task.action = module + new_task.action = self._module action = self._shared_loader_obj.action_loader.get( self._rm_play_context.network_os, @@ -108,12 +121,14 @@ def _run_resource_module(self): templar=self._templar, shared_loader_obj=self._shared_loader_obj, ) - display.vvvv("Running resource module %s" % module) + display.vvvv("Running resource module %s" % self._module) for option in ["os_name", "name"]: if option in new_task.args: new_task.args.pop(option) - return action.run(task_vars=self._task_vars) + result = action.run(task_vars=self._task_vars) + result.update({"resource_module_name": self._module}) + return result def _get_resource_module(self): if "." in self._name: diff --git a/plugins/modules/network_resource.py b/plugins/modules/network_resource.py index 394d463e1..3f53cf037 100644 --- a/plugins/modules/network_resource.py +++ b/plugins/modules/network_resource.py @@ -11,7 +11,7 @@ DOCUMENTATION = """ module: network_resource -author: +author: - Ganesh B. Nalawade (@ganeshrn) short_description: Manage resource modules description: @@ -23,10 +23,10 @@ type: str description: - The name of the os to manage the resource modules. - - The name should be fully qualified collection name format, + - The name should be fully qualified collection name format, that is I(..). - If value of this option is not set the os value will be - read from I(ansible_network_os) variable. + read from I(ansible_network_os) variable. - If value of both I(os_name) and I(ansible_network_os) is not set it will result in error. name: @@ -36,7 +36,7 @@ - The resource module should be supported for given I(os_name), if not supported it will result in error. config: - description: + description: - The resource module configuration. For details on the type and structure of this option refer the individual resource module platform documentation. @@ -66,7 +66,7 @@ ansible.netcommon.network_resource: register: result -- name: fetch acl config for +- name: fetch acl config for ansible.netcommon.network_resource: os_name: cisco.ios.ios name: acls