Browse code

corrected no_log for items and skipped tasks corrected output from default callback added new tests for no_log loops updated makefile test to check for both positive and negative occurrences of no_log

Brian Coca authored on 2015/10/03 03:33:02
Showing 5 changed files
... ...
@@ -277,7 +277,7 @@ class TaskExecutor:
277 277
         # variable not being present which would otherwise cause validation to fail
278 278
         if not self._task.evaluate_conditional(templar, variables):
279 279
             self._display.debug("when evaulation failed, skipping this task")
280
-            return dict(changed=False, skipped=True, skip_reason='Conditional check failed')
280
+            return dict(changed=False, skipped=True, skip_reason='Conditional check failed', _ansible_no_log=self._play_context.no_log)
281 281
 
282 282
         # Now we do final validation on the task, which sets all fields to their final values.
283 283
         # In the case of debug tasks, we save any 'var' params and restore them after validating
... ...
@@ -108,15 +108,14 @@ class CallbackBase:
108 108
                 ret.append(">> the files are different, but the diff library cannot compare unicode strings\n\n")
109 109
 
110 110
     def _get_item(self, result):
111
-        if '_ansible_no_log' in result:
111
+        if '_ansible_no_log' in result and result['_ansible_no_log']:
112 112
             item = "(censored due to no_log)"
113 113
         else:
114
-            item = getattr(result, 'item', "(censored due to no_log)")
114
+            item = result['item']
115 115
 
116 116
         return item
117 117
 
118 118
     def _process_items(self, result):
119
-
120 119
         for res in result._result['results']:
121 120
             newres = deepcopy(result)
122 121
             res['item'] = self._get_item(res)
... ...
@@ -88,13 +88,13 @@ class CallbackModule(CallbackBase):
88 88
 
89 89
     def v2_runner_on_skipped(self, result):
90 90
         if C.DISPLAY_SKIPPED_HOSTS:
91
-            msg = "skipping: [%s]" % result._host.get_name()
92 91
             if result._task.loop and 'results' in result._result:
93 92
                 self._process_items(result)
94 93
             else:
94
+                msg = "skipping: [%s]" % result._host.get_name()
95 95
                 if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and not '_ansible_verbose_override' in result._result:
96 96
                     msg += " => %s" % self._dump_results(result._result)
97
-            self._display.display(msg, color='cyan')
97
+                self._display.display(msg, color='cyan')
98 98
 
99 99
     def v2_runner_on_unreachable(self, result):
100 100
         if result._task.delegate_to:
... ...
@@ -192,5 +192,6 @@ test_lookup_paths:
192 192
 	ansible-playbook lookup_paths/play.yml -i $(INVENTORY) -v $(TEST_FLAGS)
193 193
 
194 194
 no_log:
195
-	[ "$$(ansible-playbook no_log_local.yml -i $(INVENTORY) -vvvvv | grep DO_NOT_LOG)" = "" ]
195
+	# This test expects 7 loggable vars and 0 non loggable ones, if either mismatches it fails, run the ansible-playbook command to debug
196
+	[ "$$(ansible-playbook no_log_local.yml -i $(INVENTORY) -vvvvv | awk -e 'BEGIN { logme = 0; nolog = 0; } /LOG_ME/ { logme += 1;} /DO_NOT_LOG/ { nolog += 1;} END { printf "%d/%d", logme, nolog; }')" = "7/0" ]
196 197
 
... ...
@@ -16,10 +16,11 @@
16 16
       failed_when: true
17 17
       ignore_errors: true
18 18
 
19
-    - name: failed item args should be logged in the absence of no_log
19
+    - name: item args should be logged in the absence of no_log
20 20
       shell: echo {{ item }}
21
-      with_items: [ "LOG_ME_ITEM_FAILED" ]
22
-      failed_when: true
21
+      with_items: [ "LOG_ME_ITEM", "LOG_ME_SKIPPED", "LOG_ME_ITEM_FAILED" ]
22
+      when: item != "LOG_ME_SKIPPED"
23
+      failed_when: item == "LOG_ME_ITEM_FAILED"
23 24
       ignore_errors: true
24 25
 
25 26
     - name: args should not be logged when task-level no_log set
... ...
@@ -49,11 +50,13 @@
49 49
       no_log: true
50 50
       when: false
51 51
 
52
-    - name: skipped item args should be suppressed with no_log
52
+    - name: items args should be suppressed with no_log in every state
53 53
       shell: echo {{ item }}
54 54
       no_log: true
55
-      with_items: [ "DO_NOT_LOG_ITEM_SKIPPED", "DO_NOT_LOG_ITEM_SKIPPED_2" ]
56
-      when: item == False
55
+      with_items: [ "DO_NOT_LOG_ITEM", "DO_NOT_LOG_ITEM_SKIPPED", "DO_NOT_LOG_ITEM_FAILED" ]
56
+      when: item != "DO_NOT_LOG_ITEM_SKIPPED"
57
+      failed_when: item == "DO_NOT_LOG_ITEM_FAILED"
58
+      ignore_errors: yes
57 59
 
58 60
     - name: async task args should suppressed with no_log
59 61
       async: 10