diff --git a/lib/ansible/playbook/attribute.py b/lib/ansible/playbook/attribute.py index 8a727a01930..b2e89c7733e 100644 --- a/lib/ansible/playbook/attribute.py +++ b/lib/ansible/playbook/attribute.py @@ -21,12 +21,13 @@ __metaclass__ = type class Attribute: - def __init__(self, isa=None, private=False, default=None, required=False): + def __init__(self, isa=None, private=False, default=None, required=False, listof=None): self.isa = isa self.private = private self.default = default self.required = required + self.listof = listof class FieldAttribute(Attribute): pass diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py index 2d931748ebb..e33bedf3c86 100644 --- a/lib/ansible/playbook/base.py +++ b/lib/ansible/playbook/base.py @@ -274,6 +274,10 @@ class Base: elif attribute.isa == 'list': if not isinstance(value, list): value = [ value ] + if attribute.listof is not None: + for item in value: + if not isinstance(item, attribute.listof): + raise AnsibleParserError("the field '%s' should be a list of %s, but the item '%s' is a %s" % (name, attribute.listof, item, type(item)), obj=self.get_ds()) elif attribute.isa == 'dict' and not isinstance(value, dict): raise TypeError() diff --git a/lib/ansible/playbook/taggable.py b/lib/ansible/playbook/taggable.py index 40e05d1817a..6ddd4b7439a 100644 --- a/lib/ansible/playbook/taggable.py +++ b/lib/ansible/playbook/taggable.py @@ -19,6 +19,8 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +from six import string_types + from ansible.errors import AnsibleError from ansible.playbook.attribute import FieldAttribute from ansible.template import Templar @@ -26,7 +28,7 @@ from ansible.template import Templar class Taggable: untagged = set(['untagged']) - _tags = FieldAttribute(isa='list', default=[]) + _tags = FieldAttribute(isa='list', default=[], listof=(string_types,int)) def __init__(self): super(Taggable, self).__init__()