From 6587078da426b6383675dd83f57cf82d2c79bae8 Mon Sep 17 00:00:00 2001 From: Teddy Caddy Date: Mon, 26 Sep 2022 11:16:32 -0400 Subject: [PATCH] Fix `cannot import name 'cli' from '__main__'` error * Closes #69 --- datadog_callback.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/datadog_callback.py b/datadog_callback.py index a4f2f08..f62003a 100644 --- a/datadog_callback.py +++ b/datadog_callback.py @@ -16,7 +16,10 @@ import ansible from ansible.plugins.callback import CallbackBase -from __main__ import cli +try: + from __main__ import cli +except ImportError: + cli = False ANSIBLE_ABOVE_28 = False if IMPORT_ERROR is None and version.parse(ansible.__version__) >= version.parse('2.8.0'): @@ -43,10 +46,10 @@ def __init__(self): self._playbook_name = None self._start_time = time.time() self._options = None - if IMPORT_ERROR is None and cli: + if IMPORT_ERROR is None: if ANSIBLE_ABOVE_28: self._options = CLIARGS - else: + elif cli: self._options = cli.options # self.playbook is set in the `v2_playbook_on_start` callback method