From 28b9fd4e30c77ffbeefd6cfa0499854750fd43a8 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Fri, 3 Jan 2014 13:46:31 -0500 Subject: [PATCH] We have had only_if, when_foo, etc, deprecated for a while and said they would be removed in 1.5. Now they are, with friendly error messages still. Users of these features should use "when:" as documented at docs.ansible.com. Similarly, include + with_items has been removed. The solution is to loop inside the task files, see with_nested / with_together, etc. --- lib/ansible/playbook/__init__.py | 2 +- lib/ansible/playbook/play.py | 9 ++------- lib/ansible/playbook/task.py | 4 ++-- lib/ansible/utils/__init__.py | 17 +++++++++++++---- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 36788f2409..e2bd662618 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -161,7 +161,7 @@ class PlayBook(object): play_basedirs = [] if type(playbook_data) != list: - raise errors.AnsibleError("parse error: playbooks must be formatted as a YAML list") + raise errors.AnsibleError("parse error: playbooks must be formatted as a YAML list, got %s" % type(playbook_data)) basedir = os.path.dirname(path) or '.' utils.plugins.push_basedir(basedir) diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index a2fdc643f2..cb8665dcf5 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -484,14 +484,9 @@ class Play(object): include_vars = {} for k in x: if k.startswith("with_"): - utils.deprecated("include + with_items is an unsupported feature and has been undocumented for many releases because of this", "1.5") - plugin_name = k[5:] - if plugin_name not in utils.plugins.lookup_loader: - raise errors.AnsibleError("cannot find lookup plugin named %s for usage in with_%s" % (plugin_name, plugin_name)) - terms = template(self.basedir, x[k], task_vars) - items = utils.plugins.lookup_loader.get(plugin_name, basedir=self.basedir, runner=None).run(terms, inject=task_vars) + utils.deprecated("include + with_items is a removed deprecated feature", "1.5", removed=True) elif k.startswith("when_"): - included_additional_conditions.insert(0, utils.compile_when_to_only_if("%s %s" % (k[5:], x[k]))) + utils.deprecated("\"when_:\" is a removed deprecated feature, use the simplified 'when:' conditional directly", None, removed=True) elif k == 'when': if type(x[k]) is str: included_additional_conditions.insert(0, utils.compile_when_to_only_if("jinja2_compare %s" % x[k])) diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index 849a1b26ab..be26c8f699 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -98,7 +98,7 @@ class Task(object): utils.warning("It is unneccessary to use '{{' in conditionals, leave variables in loop expressions bare.") ds[x] = "jinja2_compare %s" % (ds[x]) 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 has been removed. Switch to using the regular unified 'when' statements as described in ansibleworks.com/docs/.","1.5", removed=True) if 'when' in ds: raise errors.AnsibleError("multiple when_* statements specified in task %s" % (ds.get('name', ds['action']))) @@ -191,7 +191,7 @@ class Task(object): self.only_if = ds.get('only_if', 'True') if self.only_if != 'True': - utils.deprecated("only_if is a very old feature and has been obsolete since 0.9, please switch to the 'when' conditional as described at http://ansibleworks.com/docs","1.5") + utils.deprecated("only_if is a very old feature and has been obsolete since 0.9, please switch to the 'when' conditional as described at http://ansibleworks.com/docs","1.5",removed=True) self.when = ds.get('when', None) self.changed_when = ds.get('changed_when', None) diff --git a/lib/ansible/utils/__init__.py b/lib/ansible/utils/__init__.py index 126e86869a..9a57a2ef52 100644 --- a/lib/ansible/utils/__init__.py +++ b/lib/ansible/utils/__init__.py @@ -979,12 +979,21 @@ def listify_lookup_plugin_terms(terms, basedir, inject): return terms -def deprecated(msg, version): +def deprecated(msg, version, removed=False): ''' used to print out a deprecation message.''' - if not C.DEPRECATION_WARNINGS: + + if not removed and 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" + + if not removed: + if version: + new_msg = "\n[DEPRECATION WARNING]: %s. This feature will be removed in version %s." % (msg, version) + else: + new_msg = "\n[DEPRECATION WARNING]: %s. This feature will be removed in a future release." % (msg) + new_msg = new_msg + " Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.\n\n" + else: + raise errors.AnsibleError("[DEPRECATED]: %s. Please update your playbooks." % msg) + wrapped = textwrap.wrap(new_msg, 79) new_msg = "\n".join(wrapped) + "\n"