mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
Deprecation warnings of several flavors, nice and purple and can be disabled
in ansible.cfg.
This commit is contained in:
@@ -27,6 +27,7 @@ from ansible import errors
|
||||
from ansible import __version__
|
||||
from ansible.utils.plugins import *
|
||||
from ansible.utils import template
|
||||
from ansible.callbacks import display
|
||||
import ansible.constants as C
|
||||
import time
|
||||
import StringIO
|
||||
@@ -39,9 +40,14 @@ import difflib
|
||||
import warnings
|
||||
import traceback
|
||||
import getpass
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
VERBOSITY=0
|
||||
|
||||
# list of all deprecation messages to prevent duplicate display
|
||||
deprecations = {}
|
||||
|
||||
MAX_FILE_SIZE_FOR_DIFF=1*1024*1024
|
||||
|
||||
try:
|
||||
@@ -385,10 +391,14 @@ Or:
|
||||
if len(parts) > 1:
|
||||
middle = parts[1].strip()
|
||||
match = False
|
||||
if middle.startswith("'") and not middle.endswith('"'):
|
||||
unbalanced = False
|
||||
if middle.startswith("'") and not middle.endswith("'"):
|
||||
match = True
|
||||
elif middle.startswith('"') and not middle.endswith('"'):
|
||||
match = True
|
||||
if middle[0] in [ '"', "'" ] and middle[-1] in [ '"', "'" ]:
|
||||
unbalanced = True
|
||||
|
||||
if match:
|
||||
msg = msg + """
|
||||
This one looks easy to fix. It seems that there is a value started
|
||||
@@ -405,6 +415,22 @@ or equivalently:
|
||||
|
||||
when: "'ok' in result.stdout"
|
||||
|
||||
"""
|
||||
return msg
|
||||
|
||||
if unbalanced:
|
||||
msg = msg + """
|
||||
We could be wrong, but this one looks like it might be an issue with
|
||||
unbalanced quotes. If starting a value with a quote, make sure the
|
||||
line ends with the same set of quotes. For instance this arbitrary
|
||||
example:
|
||||
|
||||
foo: "bad" "wolf"
|
||||
|
||||
Could be written as:
|
||||
|
||||
foo: '"bad" "wolf"'
|
||||
|
||||
"""
|
||||
return msg
|
||||
|
||||
@@ -930,6 +956,19 @@ def listify_lookup_plugin_terms(terms, basedir, inject):
|
||||
|
||||
return terms
|
||||
|
||||
def deprecated(msg, version):
|
||||
''' used to print out a deprecation message.'''
|
||||
if not C.DEPRECATION_WARNINGS:
|
||||
return
|
||||
new_msg = "\n[DEPRECATION WARNING]: %s. This feature will be removed in version %s." % (msg, version)
|
||||
new_msg = new_msg + " Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.\n\n"
|
||||
wrapped = textwrap.wrap(new_msg, 79)
|
||||
new_msg = "\n".join(wrapped) + "\n"
|
||||
|
||||
if new_msg not in deprecations:
|
||||
display(new_msg, color='purple', stderr=True)
|
||||
deprecations[new_msg] = 1
|
||||
|
||||
def combine_vars(a, b):
|
||||
if C.DEFAULT_HASH_BEHAVIOUR == "merge":
|
||||
return merge_hash(a, b)
|
||||
|
||||
@@ -292,7 +292,13 @@ def legacy_varReplace(basedir, raw, vars, lookup_fatal=True, depth=0, expand_lis
|
||||
done.append(unicode(replacement)) # Append replacement value
|
||||
raw = raw[end:] # Continue with remainder of string
|
||||
|
||||
return ''.join(done)
|
||||
result = ''.join(done)
|
||||
|
||||
if result != raw:
|
||||
import utils
|
||||
utils.deprecated("Legacy variable subsitution, such as using ${foo} or $foo instead of {{ foo }} is currently valid but will be phased out and has been out of favor since version 1.2. This is the last of legacy features on our deprecation list. You may continue to use this if you have specific needs for now","1.6")
|
||||
return result
|
||||
|
||||
|
||||
# TODO: varname is misnamed here
|
||||
|
||||
|
||||
Reference in New Issue
Block a user