mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-02 14:40:19 -07:00
Properly template list of hosts in playbooks.
In playbooks, hosts can be a YAML list. We templated the list before converting it to a semicolon-separated string, which actually templated its repr. This converts to a string first. A basic unit test is included.
This commit is contained in:
parent
6034b5b0f3
commit
70837469c6
3 changed files with 26 additions and 6 deletions
|
@ -37,10 +37,16 @@ class Play(object):
|
|||
|
||||
# TODO: more error handling
|
||||
|
||||
hosts = ds.get('hosts')
|
||||
if hosts is None:
|
||||
raise errors.AnsibleError('hosts declaration is required')
|
||||
elif isinstance(hosts, list):
|
||||
hosts = ';'.join(hosts)
|
||||
hosts = utils.template(hosts, playbook.extra_vars, {})
|
||||
|
||||
self._ds = ds
|
||||
self.playbook = playbook
|
||||
self.hosts = ds.get('hosts', None)
|
||||
self.hosts = utils.template(self.hosts, self.playbook.extra_vars, {})
|
||||
self.hosts = hosts
|
||||
self.name = ds.get('name', self.hosts)
|
||||
self.vars = ds.get('vars', {})
|
||||
self.vars_files = ds.get('vars_files', [])
|
||||
|
@ -56,10 +62,6 @@ class Play(object):
|
|||
self._tasks = self._load_tasks(self._ds, 'tasks')
|
||||
self._handlers = self._load_tasks(self._ds, 'handlers')
|
||||
|
||||
if self.hosts is None:
|
||||
raise errors.AnsibleError('hosts declaration is required')
|
||||
if isinstance(self.hosts, list):
|
||||
self.hosts = ';'.join(self.hosts)
|
||||
if self.sudo_user != 'root':
|
||||
self.sudo = True
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue