From 7a0b4a5117b33b14bb669bc1078360f26f3a36f6 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 5 Mar 2019 16:08:15 -0500 Subject: [PATCH] Allow user to control output of verbose messages (#52948) to stdout (default) or stderr --- changelogs/fragments/verbose_stderr.yml | 2 ++ lib/ansible/config/base.yml | 11 +++++++++++ lib/ansible/utils/display.py | 6 ++++-- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/verbose_stderr.yml diff --git a/changelogs/fragments/verbose_stderr.yml b/changelogs/fragments/verbose_stderr.yml new file mode 100644 index 0000000000..eccf66753f --- /dev/null +++ b/changelogs/fragments/verbose_stderr.yml @@ -0,0 +1,2 @@ +minor_changes: + - allow user to force verbose messages to stderr diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index b8f099fd42..65e5802563 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -1776,4 +1776,15 @@ STRING_CONVERSION_ACTION: - section: defaults key: string_conversion_action type: string +VERBOSE_TO_STDERR: + version_added: '2.8' + description: + - Force 'verbose' option to use stderr instead of stdout + default: False + env: + - name: ANSIBLE_VERBOSE_TO_STDERR + ini: + - section: defaults + key: verbose_to_stderr + type: bool ... diff --git a/lib/ansible/utils/display.py b/lib/ansible/utils/display.py index f08451fc92..e5895dcac0 100644 --- a/lib/ansible/utils/display.py +++ b/lib/ansible/utils/display.py @@ -201,11 +201,13 @@ class Display(with_metaclass(Singleton, object)): self.display("%6d %0.5f [%s]: %s" % (os.getpid(), time.time(), host, msg), color=C.COLOR_DEBUG) def verbose(self, msg, host=None, caplevel=2): + + to_stderr = C.VERBOSE_TO_STDERR if self.verbosity > caplevel: if host is None: - self.display(msg, color=C.COLOR_VERBOSE) + self.display(msg, color=C.COLOR_VERBOSE, stderr=to_stderr) else: - self.display("<%s> %s" % (host, msg), color=C.COLOR_VERBOSE) + self.display("<%s> %s" % (host, msg), color=C.COLOR_VERBOSE, stderr=to_stderr) def deprecated(self, msg, version=None, removed=False): ''' used to print out a deprecation message.'''