diff options
author | Brian Coca <bcoca@users.noreply.github.com> | 2017-04-24 15:19:52 -0400 |
---|---|---|
committer | Brian Coca <brian.coca+git@gmail.com> | 2017-04-24 15:19:50 -0400 |
commit | 476e8c71363ec81f98a2b6f0ae53039c15ebbd04 (patch) | |
tree | 74d35e104763df589e9aa0947e8b4f96ca7025ae | |
parent | 2ca4155f23c9b3f91c27ab3b38c40fae7ef6c4eb (diff) | |
download | ansible-476e8c71363ec81f98a2b6f0ae53039c15ebbd04.tar.gz |
avoid hosts 'pre templated warnings' (#23878)
* avoid hosts 'pre templated warnings'
fixed is_template failing on undefined
fixes #23057
* py3 compat
(cherry picked from commit a108f0fcd3585ef39f0382a0108bee902d829ba4)
-rw-r--r-- | lib/ansible/template/__init__.py | 4 | ||||
-rw-r--r-- | lib/ansible/vars/__init__.py | 7 |
2 files changed, 8 insertions, 3 deletions
diff --git a/lib/ansible/template/__init__.py b/lib/ansible/template/__init__.py index f349870747..f7d54604c1 100644 --- a/lib/ansible/template/__init__.py +++ b/lib/ansible/template/__init__.py @@ -493,8 +493,8 @@ class Templar: ''' lets us know if data has a template''' if isinstance(data, string_types): try: - new = self.do_template(data) - except UndefinedError: + new = self.do_template(data, fail_on_undefined=True) + except (AnsibleUndefinedVariable, UndefinedError): return True except: return False diff --git a/lib/ansible/vars/__init__.py b/lib/ansible/vars/__init__.py index 68bee61e2e..8e6f394458 100644 --- a/lib/ansible/vars/__init__.py +++ b/lib/ansible/vars/__init__.py @@ -420,8 +420,13 @@ class VariableManager: variables['inventory_dir'] = self._inventory.basedir() variables['inventory_file'] = self._inventory.src() if play: + templar = Templar(loader=loader) + if templar.is_template(play.hosts): + pattern = 'all' + else: + pattern = play.hosts or 'all' # add the list of hosts in the play, as adjusted for limit/filters - variables['ansible_play_hosts_all'] = [x.name for x in self._inventory.get_hosts(pattern=play.hosts or 'all', ignore_restrictions=True)] + variables['ansible_play_hosts_all'] = [x.name for x in self._inventory.get_hosts(pattern=pattern, ignore_restrictions=True)] variables['ansible_play_hosts'] = [x for x in variables['ansible_play_hosts_all'] if x not in play._removed_hosts] variables['ansible_play_batch'] = [x.name for x in self._inventory.get_hosts() if x.name not in play._removed_hosts] |