Properly handle FieldAttribute.default if callable (#48992)
* Properly handle FieldAttribute.default if callable Fixes #48673 * Add changelog... * Add integration test * Add aliases file
This commit is contained in:
parent
46b465283c
commit
48ffd8789f
5 changed files with 20 additions and 2 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- Fix using omit on play keywords (https://github.com/ansible/ansible/issues/48673)
|
|
@ -363,6 +363,9 @@ class FieldAttributeBase(with_metaclass(BaseMeta, object)):
|
||||||
# if this evaluated to the omit value, set the value back to
|
# if this evaluated to the omit value, set the value back to
|
||||||
# the default specified in the FieldAttribute and move on
|
# the default specified in the FieldAttribute and move on
|
||||||
if omit_value is not None and value == omit_value:
|
if omit_value is not None and value == omit_value:
|
||||||
|
if callable(attribute.default):
|
||||||
|
setattr(self, name, attribute.default())
|
||||||
|
else:
|
||||||
setattr(self, name, attribute.default)
|
setattr(self, name, attribute.default)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -545,6 +548,9 @@ class FieldAttributeBase(with_metaclass(BaseMeta, object)):
|
||||||
for (name, attribute) in iteritems(self._valid_attrs):
|
for (name, attribute) in iteritems(self._valid_attrs):
|
||||||
if name in data:
|
if name in data:
|
||||||
setattr(self, name, data[name])
|
setattr(self, name, data[name])
|
||||||
|
else:
|
||||||
|
if callable(attribute.default):
|
||||||
|
setattr(self, name, attribute.default())
|
||||||
else:
|
else:
|
||||||
setattr(self, name, attribute.default)
|
setattr(self, name, attribute.default)
|
||||||
|
|
||||||
|
|
4
test/integration/targets/omit/48673.yml
Normal file
4
test/integration/targets/omit/48673.yml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
- hosts: localhost
|
||||||
|
serial: "{{ testing_omitted_variable | default(omit) }}"
|
||||||
|
tasks:
|
||||||
|
- debug:
|
1
test/integration/targets/omit/aliases
Normal file
1
test/integration/targets/omit/aliases
Normal file
|
@ -0,0 +1 @@
|
||||||
|
shippable/posix/group3
|
5
test/integration/targets/omit/runme.sh
Executable file
5
test/integration/targets/omit/runme.sh
Executable file
|
@ -0,0 +1,5 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
ansible-playbook 48673.yml -i ../../inventory -v "$@"
|
Loading…
Reference in a new issue