From 2a7c87a3b72d75b241cb6b819952b2b198adb567 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Fri, 16 Sep 2016 22:04:22 -0400 Subject: [PATCH] fixes AttributeError: 'Task' object has no attribute '_block' This addresses a problem when *_config or *_template network modules are being used in roles. The module will error with the above message. This fixes that problem fixed ansible/ansible-modules-core#4840 --- lib/ansible/plugins/action/net_config.py | 9 +++++---- lib/ansible/plugins/action/net_template.py | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/ansible/plugins/action/net_config.py b/lib/ansible/plugins/action/net_config.py index 489f872ffb0..d36f09a65fd 100644 --- a/lib/ansible/plugins/action/net_config.py +++ b/lib/ansible/plugins/action/net_config.py @@ -108,10 +108,11 @@ class ActionModule(ActionBase): searchpath = [working_path] if self._task._role is not None: searchpath.append(self._task._role._role_path) - dep_chain = self._task._block.get_dep_chain() - if dep_chain is not None: - for role in dep_chain: - searchpath.append(role._role_path) + if hasattr(self._task, "_block:"): + dep_chain = self._task._block.get_dep_chain() + if dep_chain is not None: + for role in dep_chain: + searchpath.append(role._role_path) searchpath.append(os.path.dirname(source)) self._templar.environment.loader.searchpath = searchpath self._task.args['src'] = self._templar.template(template_data) diff --git a/lib/ansible/plugins/action/net_template.py b/lib/ansible/plugins/action/net_template.py index f76506aaaec..58a89f1ed22 100644 --- a/lib/ansible/plugins/action/net_template.py +++ b/lib/ansible/plugins/action/net_template.py @@ -101,10 +101,11 @@ class ActionModule(ActionBase): searchpath = [working_path] if self._task._role is not None: searchpath.append(self._task._role._role_path) - dep_chain = self._task._block.get_dep_chain() - if dep_chain is not None: - for role in dep_chain: - searchpath.append(role._role_path) + if hasattr(self._task, "_block:"): + dep_chain = self._task._block.get_dep_chain() + if dep_chain is not None: + for role in dep_chain: + searchpath.append(role._role_path) searchpath.append(os.path.dirname(source)) self._templar.environment.loader.searchpath = searchpath self._task.args['src'] = self._templar.template(template_data)