Always load group_vars and host_vars.

This commit is contained in:
Dave Peticolas 2012-08-13 20:36:51 -07:00
parent 7ab0d60b1a
commit b42e835aab
6 changed files with 27 additions and 12 deletions

View file

@ -284,7 +284,6 @@ class PlayBook(object):
# let runner template out future commands
setup_ok = setup_results.get('contacted', {})
for (host, result) in setup_ok.iteritems():
facts = result.get('ansible_facts', {})
self.SETUP_CACHE[host] = result.get('ansible_facts', {})
return setup_results
@ -299,14 +298,12 @@ class PlayBook(object):
self.callbacks.on_play_start(play.name)
# get facts from system
rc = self._do_setup_step(play)
self._do_setup_step(play)
# now with that data, handle contentional variable file imports!
if play.vars_files and len(play.vars_files) > 0:
play.update_vars_files(self.inventory.list_hosts(play.hosts))
play.update_vars_files(self.inventory.list_hosts(play.hosts))
for task in play.tasks():
# only run the task if the requested tags match
should_run = False
for x in self.only_tags:
@ -323,4 +320,3 @@ class PlayBook(object):
self.inventory.restrict_to(handler.notified_by)
self._run_task(play, handler, True)
self.inventory.lift_restriction()

View file

@ -25,9 +25,6 @@ class TestCallbacks(object):
def on_start(self):
EVENTS.append('start')
def on_setup(self):
EVENTS.append([ 'primary_setup' ])
def on_skipped(self, host, item=None):
EVENTS.append([ 'skipped', [ host ]])
@ -46,9 +43,6 @@ class TestCallbacks(object):
def on_task_start(self, name, is_conditional):
EVENTS.append([ 'task start', [ name, is_conditional ]])
def on_unreachable(self, host, msg):
EVENTS.append([ 'unreachable', [ host, msg ]])
def on_failed(self, host, results, ignore_errors):
EVENTS.append([ 'failed', [ host, results, ignore_errors ]])
@ -161,6 +155,19 @@ class TestPlaybook(unittest.TestCase):
print data
assert data.find("ears") != -1, "template success"
def test_playbook_vars(self):
test_callbacks = TestCallbacks()
playbook = ansible.playbook.PlayBook(
playbook=os.path.join(self.test_dir, 'test_playbook_vars', 'playbook.yml'),
host_list='test/test_playbook_vars/hosts',
stats=ans_callbacks.AggregateStats(),
callbacks=test_callbacks,
runner_callbacks=test_callbacks
)
playbook.run()
assert playbook.SETUP_CACHE['host1'] == {'attr2': 2, 'attr1': 1}
assert playbook.SETUP_CACHE['host2'] == {'attr2': 2}
def test_yaml_hosts_list(self):
# Make sure playbooks support hosts: [host1, host2]
# TODO: Actually run the play on more than one host

View file

@ -0,0 +1,2 @@
---
attr2: 2

View file

@ -0,0 +1,2 @@
---
attr1: 1

View file

@ -0,0 +1,6 @@
host1
host2
[group]
host1
host2

View file

@ -0,0 +1,2 @@
---
- hosts: group