From 3c2cbae68eb33468e69bfa64a089501370dcc2f9 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Tue, 17 Jul 2012 19:09:36 -0400 Subject: [PATCH] Plays and tasks now yell when they see parameters they do not understand, so that typos like 'var' for 'vars' don't result in people having to ask questions about what is wrong with their playbook --- CHANGELOG.md | 1 + lib/ansible/playbook/play.py | 12 ++++++++++++ lib/ansible/playbook/task.py | 10 ++++++++++ 3 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7518d455b5..77bd6aea1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ Ansible Changes By Release * ec2 inventory script * mount module * apt module now passes DEBIAN_FRONTEND=noninteractive +* to catch typos, like 'var' for 'vars', playbooks and tasks now yell on invalid parameters 0.5 "Amsterdam" ------- July 04, 2012 diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index e2be4748d6..0a56e4b8f6 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -32,11 +32,23 @@ class Play(object): 'tags', 'gather_facts', '_ds', '_handlers', '_tasks' ] + # to catch typos and so forth -- these are userland names + # and don't line up 1:1 with how they are stored + VALID_KEYS = [ + 'hosts', 'name', 'vars', 'vars_prompt', 'vars_files', + 'tasks', 'handlers', 'user', 'port', 'include', + 'sudo', 'sudo_user', 'connection', 'tags', 'gather_facts' + ] + # ************************************************* def __init__(self, playbook, ds): ''' constructor loads from a play datastructure ''' + for x in ds.keys(): + if not x in Play.VALID_KEYS: + raise errors.AnsibleError("%s is not a legal parameter in an Ansible Playbook" % x) + # TODO: more error handling hosts = ds.get('hosts') diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index 378ab103f3..1a8323fa94 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -26,9 +26,19 @@ class Task(object): 'play', 'notified_by', 'tags', 'with_items', 'first_available_file' ] + # to prevent typos and such + VALID_KEYS = [ + 'name', 'action', 'only_if', 'async', 'poll', 'notify', 'with_items', 'first_available_file', + 'include', 'tags' + ] + def __init__(self, play, ds, module_vars=None): ''' constructor loads from a task or handler datastructure ''' + for x in ds.keys(): + if not x in Task.VALID_KEYS: + raise errors.AnsibleError("%s is not a legal parameter in an Ansible task or handler" % x) + self.module_vars = module_vars self.play = play