Commit a45494a8 by Michael DeHaan

Add warnings feature.

parent 9637f620
...@@ -81,6 +81,10 @@ class Task(object): ...@@ -81,6 +81,10 @@ class Task(object):
# code to allow "with_glob" and to reference a lookup plugin named glob # code to allow "with_glob" and to reference a lookup plugin named glob
elif x.startswith("with_"): elif x.startswith("with_"):
if isinstance(ds[x], basestring) and '{{' in ds[x]:
utils.warning("It is unneccessary to use '{{' in loops, leave variables in loop expressions bare.")
plugin_name = x.replace("with_","") plugin_name = x.replace("with_","")
if plugin_name in utils.plugins.lookup_loader: if plugin_name in utils.plugins.lookup_loader:
ds['items_lookup_plugin'] = plugin_name ds['items_lookup_plugin'] = plugin_name
...@@ -90,6 +94,8 @@ class Task(object): ...@@ -90,6 +94,8 @@ class Task(object):
raise errors.AnsibleError("cannot find lookup plugin named %s for usage in with_%s" % (plugin_name, plugin_name)) raise errors.AnsibleError("cannot find lookup plugin named %s for usage in with_%s" % (plugin_name, plugin_name))
elif x in [ 'changed_when', 'failed_when', 'when']: elif x in [ 'changed_when', 'failed_when', 'when']:
if isinstance(ds[x], basestring) and '{{' in ds[x]:
utils.warning("It is unneccessary to use '{{' in conditionals, leave variables in loop expressions bare.")
ds[x] = "jinja2_compare %s" % (ds[x]) ds[x] = "jinja2_compare %s" % (ds[x])
elif x.startswith("when_"): elif x.startswith("when_"):
utils.deprecated("The 'when_' conditional is a deprecated syntax as of 1.2. Switch to using the regular unified 'when' statements as described in ansibleworks.com/docs/.","1.5") utils.deprecated("The 'when_' conditional is a deprecated syntax as of 1.2. Switch to using the regular unified 'when' statements as described in ansibleworks.com/docs/.","1.5")
......
...@@ -47,6 +47,7 @@ VERBOSITY=0 ...@@ -47,6 +47,7 @@ VERBOSITY=0
# list of all deprecation messages to prevent duplicate display # list of all deprecation messages to prevent duplicate display
deprecations = {} deprecations = {}
warnings = {}
MAX_FILE_SIZE_FOR_DIFF=1*1024*1024 MAX_FILE_SIZE_FOR_DIFF=1*1024*1024
...@@ -969,7 +970,16 @@ def deprecated(msg, version): ...@@ -969,7 +970,16 @@ def deprecated(msg, version):
display(new_msg, color='purple', stderr=True) display(new_msg, color='purple', stderr=True)
deprecations[new_msg] = 1 deprecations[new_msg] = 1
def warning(msg):
new_msg = "\n[WARNING]: %s" % msg
wrapped = textwrap.wrap(new_msg, 79)
new_msg = "\n".join(wrapped) + "\n"
if new_msg not in warnings:
display(new_msg, color='bright purple', stderr=True)
warnings[new_msg] = 1
def combine_vars(a, b): def combine_vars(a, b):
if C.DEFAULT_HASH_BEHAVIOUR == "merge": if C.DEFAULT_HASH_BEHAVIOUR == "merge":
return merge_hash(a, b) return merge_hash(a, b)
else: else:
......
...@@ -295,7 +295,7 @@ def legacy_varReplace(basedir, raw, vars, lookup_fatal=True, depth=0, expand_lis ...@@ -295,7 +295,7 @@ def legacy_varReplace(basedir, raw, vars, lookup_fatal=True, depth=0, expand_lis
result = ''.join(done) result = ''.join(done)
if result != raw: if result != raw:
import utils from ansible 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") 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 return result
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment