Properly handle FieldAttribute.default if callable (#48992)

* Properly handle FieldAttribute.default if callable

Fixes #48673

* Add changelog...

* Add integration test

* Add aliases file

(cherry picked from commit 48ffd8789f)
This commit is contained in:
Martin Krizek 2018-11-26 18:14:46 +01:00 committed by Toshio Kuratomi
parent 255a7dab7e
commit 316d3abb42
5 changed files with 20 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- Fix using omit on play keywords (https://github.com/ansible/ansible/issues/48673)

View file

@ -366,7 +366,10 @@ class FieldAttributeBase(with_metaclass(BaseMeta, object)):
# if this evaluated to the omit value, set the value back to
# the default specified in the FieldAttribute and move on
if omit_value is not None and value == omit_value:
setattr(self, name, attribute.default)
if callable(attribute.default):
setattr(self, name, attribute.default())
else:
setattr(self, name, attribute.default)
continue
# and make sure the attribute is of the type it should be
@ -549,7 +552,10 @@ class FieldAttributeBase(with_metaclass(BaseMeta, object)):
if name in data:
setattr(self, name, data[name])
else:
setattr(self, name, attribute.default)
if callable(attribute.default):
setattr(self, name, attribute.default())
else:
setattr(self, name, attribute.default)
# restore the UUID field
setattr(self, '_uuid', data.get('uuid'))

View file

@ -0,0 +1,4 @@
- hosts: localhost
serial: "{{ testing_omitted_variable | default(omit) }}"
tasks:
- debug:

View file

@ -0,0 +1 @@
shippable/posix/group3

View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eux
ansible-playbook 48673.yml -i ../../inventory -v "$@"