diff --git a/changelogs/fragments/73926-is-template-play-hosts.yml b/changelogs/fragments/73926-is-template-play-hosts.yml new file mode 100644 index 00000000000..59c8e967785 --- /dev/null +++ b/changelogs/fragments/73926-is-template-play-hosts.yml @@ -0,0 +1,3 @@ +bugfixes: +- Variable Manager - Only check if ``play.hosts`` is a template when the play + hasn't been finalized (https://github.com/ansible/ansible/issues/73926) diff --git a/lib/ansible/playbook/base.py b/lib/ansible/playbook/base.py index 9fa84d14730..f32053a4daa 100644 --- a/lib/ansible/playbook/base.py +++ b/lib/ansible/playbook/base.py @@ -180,6 +180,10 @@ class FieldAttributeBase(with_metaclass(BaseMeta, object)): # and init vars, avoid using defaults in field declaration as it lives across plays self.vars = dict() + @property + def finalized(self): + return self._finalized + def dump_me(self, depth=0): ''' this is never called from production code, it is here to be used when debugging as a 'complex print' ''' if depth == 0: diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index 46b3885c4b8..ae20aea53c7 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -251,7 +251,7 @@ class StrategyBase: if not refresh and all((self._hosts_cache, self._hosts_cache_all)): return - if Templar(None).is_template(play.hosts): + if not play.finalized and Templar(None).is_template(play.hosts): _pattern = 'all' else: _pattern = play.hosts or 'all' diff --git a/lib/ansible/vars/manager.py b/lib/ansible/vars/manager.py index 8b2a151dde9..0715f0af94a 100644 --- a/lib/ansible/vars/manager.py +++ b/lib/ansible/vars/manager.py @@ -487,7 +487,7 @@ class VariableManager: variables['groups'] = self._inventory.get_groups_dict() if play: templar = Templar(loader=self._loader) - if templar.is_template(play.hosts): + if not play.finalized and templar.is_template(play.hosts): pattern = 'all' else: pattern = play.hosts or 'all'