From 494f9327734b3ef9d2b4e4f2a32d1d4c363cd400 Mon Sep 17 00:00:00 2001 From: Sloane Hertel <19572925+s-hertel@users.noreply.github.com> Date: Thu, 21 Apr 2022 10:26:08 -0400 Subject: [PATCH] Deprecate PlayContext.verbosity (#77507) display.verbosity should be used instead --- .../77507-deprecate-pc-verbosity.yml | 2 ++ lib/ansible/playbook/play_context.py | 21 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/77507-deprecate-pc-verbosity.yml diff --git a/changelogs/fragments/77507-deprecate-pc-verbosity.yml b/changelogs/fragments/77507-deprecate-pc-verbosity.yml new file mode 100644 index 00000000000..f3d59a0e46c --- /dev/null +++ b/changelogs/fragments/77507-deprecate-pc-verbosity.yml @@ -0,0 +1,2 @@ +deprecated_features: + - PlayContext.verbosity is deprecated and will be removed in 2.18. Use ansible.utils.display.Display().verbosity as the single source of truth. diff --git a/lib/ansible/playbook/play_context.py b/lib/ansible/playbook/play_context.py index 1918a1931e6..add9d0f143f 100644 --- a/lib/ansible/playbook/play_context.py +++ b/lib/ansible/playbook/play_context.py @@ -109,7 +109,6 @@ class PlayContext(Base): _prompt = FieldAttribute(isa='string') # general flags - _verbosity = FieldAttribute(isa='int', default=0) _only_tags = FieldAttribute(isa='set', default=set) _skip_tags = FieldAttribute(isa='set', default=set) @@ -119,6 +118,22 @@ class PlayContext(Base): # "PlayContext.force_handlers should not be used, the calling code should be using play itself instead" _force_handlers = FieldAttribute(isa='bool', default=False) + @property + def verbosity(self): + display.deprecated( + "PlayContext.verbosity is deprecated, use ansible.utils.display.Display.verbosity instead.", + version=2.18 + ) + return self._internal_verbosity + + @verbosity.setter + def verbosity(self, value): + display.deprecated( + "PlayContext.verbosity is deprecated, use ansible.utils.display.Display.verbosity instead.", + version=2.18 + ) + self._internal_verbosity = value + def __init__(self, play=None, passwords=None, connection_lockfd=None): # Note: play is really not optional. The only time it could be omitted is when we create # a PlayContext just so we can invoke its deserialize method to load it from a serialized @@ -143,6 +158,8 @@ class PlayContext(Base): # set options before play to allow play to override them if context.CLIARGS: self.set_attributes_from_cli() + else: + self._internal_verbosity = 0 if play: self.set_attributes_from_play(play) @@ -173,7 +190,7 @@ class PlayContext(Base): # From the command line. These should probably be used directly by plugins instead # For now, they are likely to be moved to FieldAttribute defaults self.private_key_file = context.CLIARGS.get('private_key_file') # Else default - self.verbosity = context.CLIARGS.get('verbosity') # Else default + self._internal_verbosity = context.CLIARGS.get('verbosity') # Else default # Not every cli that uses PlayContext has these command line args so have a default self.start_at_task = context.CLIARGS.get('start_at_task', None) # Else default