mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +00: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:
@@ -172,3 +172,16 @@ class TestPlaybook(unittest.TestCase):
|
||||
print data
|
||||
assert data.find("ears") != -1, "template success"
|
||||
|
||||
def test_yaml_hosts_list(self):
|
||||
# Make sure playbooks support hosts: [host1, host2]
|
||||
# TODO: Actually run the play on more than one host
|
||||
test_callbacks = TestCallbacks()
|
||||
playbook = ansible.playbook.PlayBook(
|
||||
playbook=os.path.join(self.test_dir, 'hosts_list.yml'),
|
||||
host_list='test/ansible_hosts',
|
||||
stats=ans_callbacks.AggregateStats(),
|
||||
callbacks=test_callbacks,
|
||||
runner_callbacks=test_callbacks
|
||||
)
|
||||
play = ansible.playbook.Play(playbook, playbook.playbook[0])
|
||||
assert play.hosts == ';'.join(('host1', 'host2', 'host3'))
|
||||
|
||||
5
test/hosts_list.yml
Normal file
5
test/hosts_list.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
# Test that playbooks support YAML lists of hosts.
|
||||
---
|
||||
- hosts: [host1, host2, host3]
|
||||
tasks:
|
||||
- action: command true
|
||||
Reference in New Issue
Block a user