Felix Fontein 5 days ago committed by GitHub
commit bf7d631362
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
minor_changes:
- "default callback plugin - add option to configure line width for YAML output. This allows to disable line wrapping
(https://github.com/ansible/ansible/issues/84657, https://github.com/ansible/ansible/pull/85498)."

@ -262,6 +262,24 @@ class CallbackBase(AnsiblePlugin):
return ((self._display.verbosity > verbosity or result.result.get('_ansible_verbose_always', False) is True) return ((self._display.verbosity > verbosity or result.result.get('_ansible_verbose_always', False) is True)
and result.result.get('_ansible_verbose_override', False) is False) and result.result.get('_ansible_verbose_override', False) is False)
def _get_yaml_width(self) -> t.Optional[int]:
try:
yaml_line_width = self.get_option('result_yaml_line_width')
except KeyError:
# Callback does not declare result_yaml_line_width nor extend result_format_callback
return None
if yaml_line_width == 'default':
return None
if yaml_line_width == 'no-break':
# Some very large value that effectively disables line breaks
return 0x7FFFFFFF
if yaml_line_width == 'terminal-width':
return self._display.columns
self._display.warn(f"Invalid value {yaml_line_width!r} for result_yaml_line_width")
return None
def _dump_results( def _dump_results(
self, self,
result: _c.Mapping[str, t.Any], result: _c.Mapping[str, t.Any],
@ -346,6 +364,7 @@ class CallbackBase(AnsiblePlugin):
Dumper=functools.partial(_AnsibleCallbackDumper, lossy=lossy), Dumper=functools.partial(_AnsibleCallbackDumper, lossy=lossy),
default_flow_style=False, default_flow_style=False,
indent=indent, indent=indent,
width=self._get_yaml_width(),
# sort_keys=sort_keys # This requires PyYAML>=5.1 # sort_keys=sort_keys # This requires PyYAML>=5.1
), ),
' ' * (indent or 4) ' ' * (indent or 4)
@ -415,6 +434,7 @@ class CallbackBase(AnsiblePlugin):
Dumper=functools.partial(_AnsibleCallbackDumper, lossy=lossy), Dumper=functools.partial(_AnsibleCallbackDumper, lossy=lossy),
default_flow_style=False, default_flow_style=False,
indent=indent, indent=indent,
width=self._get_yaml_width(),
# sort_keys=sort_keys # This requires PyYAML>=5.1 # sort_keys=sort_keys # This requires PyYAML>=5.1
), ),
' ' ' '

@ -41,6 +41,25 @@ class ModuleDocFragment(object):
- key: callback_result_indentation - key: callback_result_indentation
section: defaults section: defaults
version_added: '2.20' version_added: '2.20'
result_yaml_line_width:
name: Line width of YAML output
description:
- Configure the line width used for YAML. The YAML serializer will try to break longer lines.
- Set to V(default) for the PyYAML's default value, which is around 80 characters.
- Set to V(no-break) to disable line breaks.
- Set to V(terminal-width) to use the detected terminal width that is also used for other output of this callback.
type: str
default: default
choices:
- default
- no-break
- terminal-width
env:
- name: ANSIBLE_CALLBACK_YAML_LINE_WIDTH
ini:
- key: callback_result_yaml_line_width
section: defaults
version_added: '2.21'
pretty_results: pretty_results:
name: Configure output for readability name: Configure output for readability
description: description:

@ -0,0 +1,25 @@
PLAY [localhost] ***************************************************************
TASK [Output with long line] ***************************************************
ok: [localhost] =>
msg:
- This is a normal line.
- This is a very, very, verrrrrrrrrrrrrrry, veryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrrrryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
line.
- a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n
o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a
b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n
o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z
- Another normal line:
- Some nested line.
- A nested very, very, verrrrrrrrrrrrrrry, veryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy,
veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrrrryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
line.
PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

@ -0,0 +1,2 @@
+ ansible-playbook -i inventory test_long_line.yml
++ set +x

@ -0,0 +1,16 @@
PLAY [localhost] ***************************************************************
TASK [Output with long line] ***************************************************
ok: [localhost] =>
msg:
- This is a normal line.
- This is a very, very, verrrrrrrrrrrrrrry, veryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrrrryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong line.
- a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z
- Another normal line:
- Some nested line.
- A nested very, very, verrrrrrrrrrrrrrry, veryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrrrryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong line.
PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

@ -208,6 +208,14 @@ run_test result_format_yaml_indent_2 test.yml
export ANSIBLE_CALLBACK_RESULT_FORMAT=json export ANSIBLE_CALLBACK_RESULT_FORMAT=json
unset ANSIBLE_CALLBACK_RESULT_INDENTATION unset ANSIBLE_CALLBACK_RESULT_INDENTATION
export ANSIBLE_CALLBACK_RESULT_FORMAT=yaml
export ANSIBLE_CALLBACK_YAML_LINE_WIDTH=default
run_test result_format_yaml_default_break test_long_line.yml
export ANSIBLE_CALLBACK_YAML_LINE_WIDTH=no-break
run_test result_format_yaml_no_break test_long_line.yml
export ANSIBLE_CALLBACK_RESULT_FORMAT=json
unset ANSIBLE_CALLBACK_YAML_LINE_WIDTH
export ANSIBLE_CALLBACK_RESULT_FORMAT=yaml export ANSIBLE_CALLBACK_RESULT_FORMAT=yaml
export ANSIBLE_CALLBACK_FORMAT_PRETTY=1 export ANSIBLE_CALLBACK_FORMAT_PRETTY=1
run_test result_format_yaml_lossy_verbose test.yml -v run_test result_format_yaml_lossy_verbose test.yml -v

@ -0,0 +1,13 @@
---
- hosts: localhost
gather_facts: false
tasks:
- name: Output with long line
debug:
msg:
- This is a normal line.
- This is a very, very, verrrrrrrrrrrrrrry, veryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrrrryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong line.
- a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z
- Another normal line:
- Some nested line.
- A nested very, very, verrrrrrrrrrrrrrry, veryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrrrryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong line.
Loading…
Cancel
Save