@@ -39,17 +39,17 @@ def __init__(self, pb_path, arg_maker, debug_mod=None, show_progress_bar=False):
39
39
logging_lvl = logging .INFO
40
40
if debug_mod :
41
41
logging_lvl = logging .DEBUG
42
-
42
+
43
43
self .show_progress_bar = show_progress_bar
44
-
44
+
45
45
logging .basicConfig (format = "%(name)s %(asctime)s %(message)s" , \
46
46
datefmt = "%H:%M:%S" , level = logging_lvl )
47
47
48
48
self .pb_path = pb_path
49
49
self .arg_maker = arg_maker
50
50
51
51
self .logger = logging .getLogger ("RUNNER" )
52
-
52
+
53
53
log_sync = logging .getLogger ("SYNC" )
54
54
self .sync_obj = ans_sync (log_sync )
55
55
@@ -67,7 +67,7 @@ def __init__(self, pb_path, arg_maker, debug_mod=None, show_progress_bar=False):
67
67
self ._set_wrappers ()
68
68
start_ok = self ._start_ansible ()
69
69
self .logger .debug ("Ansible start ok: %s" , start_ok )
70
-
70
+
71
71
72
72
def _set_wrappers (self ):
73
73
wrp_lgr = logging .getLogger ("WRPR" )
@@ -110,7 +110,7 @@ def _set_wrappers(self):
110
110
self .execution_tree ,
111
111
self .progress_bar )
112
112
PlayIterator .add_tasks = self .iterator_add_task_wrp
113
-
113
+
114
114
115
115
def _set_wrappers_back (self ):
116
116
PlaybookCLI .run = self .pbcli_run_wrp .func
@@ -121,7 +121,18 @@ def _set_wrappers_back(self):
121
121
PlayIterator .add_tasks = self .iterator_add_task_wrp .func
122
122
if self .show_progress_bar :
123
123
PlaybookExecutor .__init__ = self .playbook_executor_wrp .func
124
-
124
+
125
+ def _except_hook (self , args , / ):
126
+ exc_type , exc_value , exc_traceback , thread = \
127
+ args .exc_type , args .exc_value , args .exc_traceback , args .thread
128
+
129
+ if (exc_type == SystemExit or
130
+ # NOTE: this probably should never happen
131
+ thread != self .ansible_thread ):
132
+ return self ._old_except_hook (args )
133
+
134
+ self .sync_obj .exception = exc_value
135
+ self .sync_obj .continue_runner ()
125
136
126
137
def _start_ansible (self ):
127
138
args = self .arg_maker .args
@@ -131,19 +142,22 @@ def _start_ansible(self):
131
142
self .pbCLI = PlaybookCLI (args )
132
143
133
144
self .ansible_thread = threading .Thread (target = self .pbCLI .run )
145
+ self ._old_except_hook = threading .excepthook
146
+ threading .excepthook = self ._except_hook
147
+
134
148
self .ansible_thread .start ()
135
149
self .sync_obj .runner_just_wait ()
136
150
137
151
if self .sync_obj .curr_breakpoint_label == self .breakpoint_labeles ["before_playbook" ]:
138
152
return True
139
-
153
+
140
154
return False
141
-
155
+
142
156
143
157
def has_next_play (self ):
144
158
if self .sync_obj .curr_breakpoint_label == self .breakpoint_labeles ["after_playbook" ]:
145
159
return False
146
-
160
+
147
161
self .sync_obj .continue_ansible_with_stop ()
148
162
current_bp_label = self .sync_obj .curr_breakpoint_label
149
163
self .logger .debug ("has_next_play: %s" , current_bp_label )
@@ -180,18 +194,18 @@ def run_next_task(self):
180
194
181
195
if current_bp_label != self .breakpoint_labeles ["after_task" ]:
182
196
self .logger .debug ("run_next_task() has come not in to the 'after_task'" )
183
-
197
+
184
198
for task_result_ansible_obj in self .update_conn_wrapper .current_results :
185
199
res .append (TaskResult (task_result_ansible_obj ))
186
200
187
201
self .task_wrp .set_next_to_prev ()
188
202
189
203
return res
190
-
204
+
191
205
192
206
def rerun_last_task (self ):
193
207
self .task_wrp .rerun_last_task = True
194
-
208
+
195
209
196
210
# returns True and empty string if success
197
211
# False and error msg otherwise
@@ -202,7 +216,7 @@ def add_new_task(self, new_task_str, is_dict=False):
202
216
has_attrs , error_msg = cotea_utils .obj_has_attrs (prev_task , ["_parent" ])
203
217
if not has_attrs :
204
218
return False , error_msg
205
-
219
+
206
220
curr_block = prev_task ._parent
207
221
block_attrs = ["_loader" , "_play" , "_role" , "_variable_manager" , "_use_handlers" ]
208
222
has_attrs , error_msg = cotea_utils .obj_has_attrs (curr_block , block_attrs )
@@ -227,16 +241,16 @@ def add_new_task(self, new_task_str, is_dict=False):
227
241
error_msg += "(from str-aka-dict to python ds): {}"
228
242
return False , error_msg .format (is_dict , str (e ))
229
243
ds = [new_task_str_dict ]
230
-
244
+
231
245
#print("DS:\n", ds)
232
-
246
+
233
247
has_attrs , _ = cotea_utils .obj_has_attrs (ds , ["__len__" ])
234
248
if not has_attrs :
235
249
error_msg = "Python repr of the input string should have "
236
250
error_msg += "__len__ attr. Maybe something wrong with input: {}\n "
237
251
error_msg += "Python repr without __len__ attr: {}"
238
252
return False , error_msg .format (new_task_str , str (ds ))
239
-
253
+
240
254
if len (ds ) != 1 :
241
255
error_msg = "You must add 1 new task. Instead you add: {}"
242
256
return False , error_msg .format (str (ds ))
@@ -261,7 +275,7 @@ def add_new_task(self, new_task_str, is_dict=False):
261
275
error_msg = "Exception during load_list_of_tasks call "
262
276
error_msg += "(creats Ansible.Task objects): {}"
263
277
return False , error_msg .format (str (e ))
264
-
278
+
265
279
has_attrs , _ = cotea_utils .obj_has_attrs (new_ansible_task , ["__len__" ])
266
280
if not has_attrs :
267
281
error_msg = "Python repr of the input string should have "
@@ -274,23 +288,23 @@ def add_new_task(self, new_task_str, is_dict=False):
274
288
error_msg = "The input '{}' has been interpreted into {} tasks "
275
289
error_msg += "instead of 1. Interpretation result: {}"
276
290
return False , error_msg .format (new_task_str , new_tasks_count , str (ds ))
277
-
291
+
278
292
#self.task_wrp.new_task_to_add = True
279
293
self .task_wrp .new_task = new_ansible_task [0 ]
280
-
294
+
281
295
adding_res , error_msg = self .task_wrp .add_tasks (new_ansible_task )
282
296
283
297
return adding_res , error_msg
284
298
285
-
299
+
286
300
def get_new_added_task (self ):
287
301
return self .task_wrp .new_task
288
302
289
-
303
+
290
304
def ignore_errors_of_next_task (self ):
291
305
self .task_wrp .next_task_ignore_errors = True
292
306
293
-
307
+
294
308
def dont_add_last_task_after_new (self ):
295
309
self .task_wrp .dont_add_last_task_after_new ()
296
310
@@ -306,31 +320,31 @@ def get_already_ignore_unrch(self):
306
320
def finish_ansible (self ):
307
321
while self .sync_obj .curr_breakpoint_label != self .breakpoint_labeles ["after_playbook" ]:
308
322
self .sync_obj .continue_ansible_with_stop ()
309
-
323
+
310
324
self .sync_obj .continue_ansible ()
311
325
self .ansible_thread .join (timeout = 5 )
312
326
self ._set_wrappers_back ()
313
-
327
+
314
328
315
329
def get_cur_play_name (self ):
316
330
return str (self .play_wrp .current_play_name )
317
-
331
+
318
332
319
333
def get_next_task (self ):
320
334
return self .task_wrp .get_next_task ()
321
335
322
336
323
337
def get_next_task_name (self ):
324
338
return str (self .task_wrp .get_next_task_name ())
325
-
339
+
326
340
327
341
def get_prev_task (self ):
328
342
return self .task_wrp .get_prev_task ()
329
-
343
+
330
344
331
345
def get_prev_task_name (self ):
332
346
return str (self .task_wrp .get_prev_task_name ())
333
-
347
+
334
348
335
349
def get_last_task_result (self ):
336
350
res = []
@@ -339,17 +353,17 @@ def get_last_task_result(self):
339
353
res .append (TaskResult (task_result_ansible_obj ))
340
354
341
355
return res
342
-
356
+
343
357
344
358
# returns True if there was an non ignored error
345
359
def was_error (self ):
346
360
return self .play_wrp .was_error
347
-
361
+
348
362
349
363
# returns list with all errors, including the ignored ones
350
364
def get_all_error_msgs (self ):
351
365
return self .update_conn_wrapper .error_msgs
352
-
366
+
353
367
354
368
# returns last error msg that wasn't ignored
355
369
def get_error_msg (self ):
@@ -361,9 +375,9 @@ def get_error_msg(self):
361
375
362
376
if errors_count > 0 :
363
377
res = self .update_conn_wrapper .error_msgs [errors_count - 1 ]
364
-
378
+
365
379
return res
366
-
380
+
367
381
368
382
def get_all_vars (self ):
369
383
variable_manager = self .play_wrp .variable_manager
@@ -419,7 +433,7 @@ def get_variable(self, var_name):
419
433
self .logger .info ("There is no variable with name %s" , var_name )
420
434
421
435
return None
422
-
436
+
423
437
424
438
def add_var_as_extra_var (self , new_var_name , value ):
425
439
variable_manager = self .play_wrp .variable_manager
0 commit comments