Unverified Commit be776dae authored by Brian Coca's avatar Brian Coca Committed by GitHub
Browse files

add static facility and apply to register (#49737)

* add static facility and apply to register

* added warning

* added test for templated register

* test register 'static' status

* rely on subshell to deal with quote context

* use corrects pb for test

* bring constants back cause new code in devel
parent ffac260c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
minor_changes:
    - add facility for playbook attributes that are not templatable, i.e register
+2 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ class Attribute:
        alias=None,
        extend=False,
        prepend=False,
        static=False,
    ):

        """
@@ -86,6 +87,7 @@ class Attribute:
        self.alias = alias
        self.extend = extend
        self.prepend = prepend
        self.static = static

        if default is not None and self.isa in _CONTAINERS and not callable(default):
            raise TypeError('defaults for FieldAttribute may not be mutable, please provide a callable instead')
+8 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ from functools import partial
from jinja2.exceptions import UndefinedError

from ansible import constants as C

from ansible.module_utils.six import iteritems, string_types, with_metaclass
from ansible.module_utils.parsing.convert_bool import boolean
from ansible.errors import AnsibleParserError, AnsibleUndefinedVariable, AnsibleAssertionError
@@ -350,6 +351,13 @@ class FieldAttributeBase(with_metaclass(BaseMeta, object)):

        for (name, attribute) in iteritems(self._valid_attrs):

            if attribute.static:
                value = getattr(self, name)
                if templar.is_template(value):
                    display.warning('"%s" is not templatable, but we found: %s, '
                                    'it will not be templated and will be used "as is".' % (name, value))
                continue

            if getattr(self, name) is None:
                if not attribute.required:
                    continue
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ class Task(Base, Conditional, Taggable, Become):
    _loop_control = FieldAttribute(isa='class', class_type=LoopControl, inherit=False)
    _notify = FieldAttribute(isa='list')
    _poll = FieldAttribute(isa='int', default=10)
    _register = FieldAttribute(isa='string')
    _register = FieldAttribute(isa='string', static=True)
    _retries = FieldAttribute(isa='int', default=3)
    _until = FieldAttribute(isa='list', default=list)

+6 −0
Original line number Diff line number Diff line
- hosts: testhost
  gather_facts: false
  tasks:
    - name: template in register warns, but no template should not
      debug: msg=unimportant
      register: thisshouldnotwarn
Loading