From c2a5cb61748984184306529c3fd7bd49fd4b86a1 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Fri, 24 Jun 2016 14:22:27 -0700 Subject: [PATCH] Fix junit callback plugin for Python 2.6. (#16440) --- lib/ansible/plugins/callback/junit.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/ansible/plugins/callback/junit.py b/lib/ansible/plugins/callback/junit.py index 14cf71699b..d5b4df6714 100644 --- a/lib/ansible/plugins/callback/junit.py +++ b/lib/ansible/plugins/callback/junit.py @@ -21,7 +21,6 @@ __metaclass__ = type import os import time -from collections import OrderedDict from ansible.plugins.callback import CallbackBase from ansible.utils.unicode import to_bytes @@ -31,6 +30,15 @@ try: except ImportError: HAS_JUNIT_XML = False +try: + from collections import OrderedDict + HAS_ORDERED_DICT = True +except ImportError: + try: + from ordereddict import OrderedDict + HAS_ORDERED_DICT = True + except ImportError: + HAS_ORDERED_DICT = False class CallbackModule(CallbackBase): """ @@ -64,7 +72,7 @@ class CallbackModule(CallbackBase): self._playbook_path = None self._playbook_name = None self._play_name = None - self._task_data = OrderedDict() + self._task_data = None self.disabled = False @@ -73,6 +81,13 @@ class CallbackModule(CallbackBase): self._display.warning('The `junit_xml` python module is not installed. ' 'Disabling the `junit` callback plugin.') + if HAS_ORDERED_DICT: + self._task_data = OrderedDict() + else: + self.disabled = True + self._display.warning('The `ordereddict` python module is not installed. ' + 'Disabling the `junit` callback plugin.') + if not os.path.exists(self._output_dir): os.mkdir(self._output_dir)