Skip to content

Commit 9f10335

Browse files
authored
Merge pull request #70 from tcaddy/master
Fix `cannot import name 'cli' from '__main__'` error
2 parents 3dffa11 + 6587078 commit 9f10335

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

datadog_callback.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
import ansible
1818
from ansible.plugins.callback import CallbackBase
19-
from __main__ import cli
19+
try:
20+
from __main__ import cli
21+
except ImportError:
22+
cli = False
2023

2124
ANSIBLE_ABOVE_28 = False
2225
if IMPORT_ERROR is None and version.parse(ansible.__version__) >= version.parse('2.8.0'):
@@ -43,10 +46,10 @@ def __init__(self):
4346
self._playbook_name = None
4447
self._start_time = time.time()
4548
self._options = None
46-
if IMPORT_ERROR is None and cli:
49+
if IMPORT_ERROR is None:
4750
if ANSIBLE_ABOVE_28:
4851
self._options = CLIARGS
49-
else:
52+
elif cli:
5053
self._options = cli.options
5154

5255
# self.playbook is set in the `v2_playbook_on_start` callback method

0 commit comments

Comments
 (0)