diff --git a/changelogs/fragments/48673-fix-omit-on-play-keywords.yaml b/changelogs/fragments/48673-fix-omit-on-play-keywords.yaml new file mode 100644 index 0000000000..90d3e27e75 --- /dev/null +++ b/changelogs/fragments/48673-fix-omit-on-play-keywords.yaml @@ -0,0 +1,2 @@ +bugfixes: + - Fix using omit on play keywords (https://github.com/ansible/ansible/issues/48673) diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py index e74bfbd557..17e15e4a96 100644 --- a/lib/ansible/playbook/base.py +++ b/lib/ansible/playbook/base.py @@ -363,7 +363,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 @@ -546,7 +549,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')) diff --git a/test/integration/targets/omit/48673.yml b/test/integration/targets/omit/48673.yml new file mode 100644 index 0000000000..b6d4f31b10 --- /dev/null +++ b/test/integration/targets/omit/48673.yml @@ -0,0 +1,4 @@ +- hosts: localhost + serial: "{{ testing_omitted_variable | default(omit) }}" + tasks: + - debug: diff --git a/test/integration/targets/omit/aliases b/test/integration/targets/omit/aliases new file mode 100644 index 0000000000..b59832142f --- /dev/null +++ b/test/integration/targets/omit/aliases @@ -0,0 +1 @@ +shippable/posix/group3 diff --git a/test/integration/targets/omit/runme.sh b/test/integration/targets/omit/runme.sh new file mode 100755 index 0000000000..962e1f0409 --- /dev/null +++ b/test/integration/targets/omit/runme.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -eux + +ansible-playbook 48673.yml -i ../../inventory -v "$@"