'Is there a way to hide/stop some output generated by debug
Looking for help to understand why I have the additional output from the debug line below:
- name: Check kernel diff
become: true
shell: "sdiff {{ item }}/pre-kernel.out {{ item }}/post-kernel.out | grep '|' | awk -F'|' '{print $2}' | xargs"
register: "kernel"
with_items: "{{work_dir}}"
- debug:
msg: "The system is now running Kernel Version {{ item.stdout }}"
when: "{{ item.changed == true }}"
with_items: "{{ kernel.results}}"
The output from msg is correct, but how can I stop/hide all the detail that appears before it:
TASK [patching : debug] ************************
[WARNING]: conditional statements should not include jinja2 templating delimiters such as {{ }} or {% %}. Found: {{ item.changed == true }}
ok: [test02] => (item={'stderr_lines': [], 'ansible_loop_var': u'item', u'end': u'2020-05-26 16:23:37.068718', u'stderr': u'', u'stdout': u'4.14.35-1902.302.2.el7uek.x86_64', u'changed': True, 'failed': False, u'delta': u'0:00:00.008894', u'cmd': u"sdiff /var/tmp/patching_2020-05-26/pre-kernel.out /var/tmp/patching_2020-05-26/post-kernel.out | grep '|' | awk -F'|' '{print $2}' | xargs", 'item': u'/var/tmp/patching_2020-05-26', u'rc': 0, u'invocation': {u'module_args': {u'warn': True, u'executable': None, u'_uses_shell': True, u'strip_empty_ends': True, u'_raw_params': u"sdiff /var/tmp/patching_2020-05-26/pre-kernel.out /var/tmp/patching_2020-05-26/post-kernel.out | grep '|' | awk -F'|' '{print $2}' | xargs", u'removes': None, u'argv': None, u'creates': None, u'chdir': None, u'stdin_add_newline': True, u'stdin': None}}, 'stdout_lines': [u'4.14.35-1902.302.2.el7uek.x86_64'], u'start': u'2020-05-26 16:23:37.059824'}) => {
"msg": "The system is now running Kernel Version 4.14.35-1902.302.2.el7uek.x86_64"
}
So it looks more like just:
TASK [patching : debug] ************************
ok: [test02] => {
"msg": "The system is now running Kernel Version 4.14.35-1902.302.2.el7uek.x86_64"
}
var_file.yml for reference:
---
work_dir:
- /var/tmp/patching_{{ansible_date_time.date}}
I've been using this as guidance.
Solution 1:[1]
without "loop_control" ansible code
- name: 'Print message if CPU utilization become abnormal'
debug:
msg:
- -------------------------------------------------------
- CPU Utilization = ( 100 - idle time ) = "{{ item.stdout }}"% is idle
- -------------------------------------------------------
#loop:
with_items:
- "{{ incidentcpuworknote_cpu }}"
- "{{ incidentcpuworknote_cpu1 }}"
- "{{ incidentcpuworknote_cpu2 }}"
when: item.stdout| int <= 10
Below is the ansible execution result before using the loop_control
TASK [Print message if CPU utilization become abnormal] ******************************************************************************************
ok: [ansiblenode] => (item={u'stderr_lines': [], u'cmd': u"mpstat -u 1 3|tail -1| awk '{print $NF}'\n", u'end': u'2021-04-03 03:37:38.417169', u'stdout': u'0.00', u'changed': True, u'failed': False, u'delta': u'0:00:03.259453', u'stderr': u'', u'rc': 0, u'stdout_lines': [u'0.00'], u'start': u'2021-04-03 03:37:35.157716'}) =>
msg:
- '-------------------------------------------------------'
- CPU Utilization = ( 100 - idle time ) = "0.00"% is idle
- '-------------------------------------------------------
with "loop_control" ansible code
Note: "loop_control" helped to avoid ansible debug messages while executing the loop
- name: 'Print message if CPU utilization become abnormal'
debug:
msg:
- -------------------------------------------------------
- CPU Utilization = ( 100 - idle time ) = "{{ item.stdout }}"% is idle
- -------------------------------------------------------
#loop:
with_items:
- "{{ incidentcpuworknote_cpu }}"
- "{{ incidentcpuworknote_cpu1 }}"
- "{{ incidentcpuworknote_cpu2 }}"
when: item.stdout| int <= 10
loop_control:
label: "{{ item.stdout }}"
Below is the ansible execution result after using the loop_control
TASK [Print message if CPU utilization become abnormal] *****************************************************
ok: [ansiblenode] => (item=0.00) =>
msg:
- '-------------------------------------------------------'
- CPU Utilization = ( 100 - idle time ) = "0.00"% is idle
- '-------------------------------------------------------'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
