1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Enabled the use of extra vars in playbook file paths when including playbooks from other playbooks.

This commit is contained in:
Tin Tvrtkovic 2013-07-18 22:45:18 +02:00
parent c3a8b6ff07
commit 4a732c1e9f
3 changed files with 29 additions and 2 deletions

View file

@ -130,7 +130,7 @@ class PlayBook(object):
self.basedir = os.path.dirname(playbook) or '.' self.basedir = os.path.dirname(playbook) or '.'
utils.plugins.push_basedir(self.basedir) utils.plugins.push_basedir(self.basedir)
vars = {} vars = extra_vars.copy()
if self.inventory.basedir() is not None: if self.inventory.basedir() is not None:
vars['inventory_dir'] = self.inventory.basedir() vars['inventory_dir'] = self.inventory.basedir()
self.filename = playbook self.filename = playbook

View file

@ -119,7 +119,8 @@ class TestPlaybook(unittest.TestCase):
filename = os.path.join(self.stage_dir, filename) filename = os.path.join(self.stage_dir, filename)
return filename return filename
def _run(self, test_playbook, host_list='test/ansible_hosts'): def _run(self, test_playbook, host_list='test/ansible_hosts',
extra_vars=None):
''' run a module and get the localhost results ''' ''' run a module and get the localhost results '''
# This ensures tests are independent of eachother # This ensures tests are independent of eachother
global EVENTS global EVENTS
@ -135,6 +136,7 @@ class TestPlaybook(unittest.TestCase):
timeout = 5, timeout = 5,
remote_user = self.user, remote_user = self.user,
remote_pass = None, remote_pass = None,
extra_vars = extra_vars,
stats = ans_callbacks.AggregateStats(), stats = ans_callbacks.AggregateStats(),
callbacks = self.test_callbacks, callbacks = self.test_callbacks,
runner_callbacks = self.test_callbacks runner_callbacks = self.test_callbacks
@ -216,6 +218,29 @@ class TestPlaybook(unittest.TestCase):
assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True) assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True)
def test_templated_includes(self):
pb = os.path.join(self.test_dir, 'playbook-templated-includer.yml')
actual = self._run(pb, extra_vars={ 'dir': self.test_dir })
# if different, this will output to screen
print "**ACTUAL**"
actual_json = utils.jsonify(actual, format=True)
print actual_json
expected = {
"localhost": {
"changed": 0,
"failures": 0,
"ok": 2,
"skipped": 0,
"unreachable": 0
}
}
expected_json = utils.jsonify(expected, format=True)
print "**EXPECTED**"
print expected_json
assert actual_json == expected_json
def test_task_includes(self): def test_task_includes(self):
pb = os.path.join(self.test_dir, 'task-includer.yml') pb = os.path.join(self.test_dir, 'task-includer.yml')
actual = self._run(pb) actual = self._run(pb)

View file

@ -0,0 +1,2 @@
---
- include: "{{dir}}/playbook-included.yml variable=foobar"