From b42e835aabeddc77722c098dc494a22340689825 Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Mon, 13 Aug 2012 20:36:51 -0700 Subject: [PATCH] Always load group_vars and host_vars. --- lib/ansible/playbook/__init__.py | 8 ++------ test/TestPlayBook.py | 19 +++++++++++++------ test/test_playbook_vars/group_vars/group | 2 ++ test/test_playbook_vars/host_vars/host1 | 2 ++ test/test_playbook_vars/hosts | 6 ++++++ test/test_playbook_vars/playbook.yml | 2 ++ 6 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 test/test_playbook_vars/group_vars/group create mode 100644 test/test_playbook_vars/host_vars/host1 create mode 100644 test/test_playbook_vars/hosts create mode 100644 test/test_playbook_vars/playbook.yml diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 118d5c11f81..f440f58e891 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -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() - diff --git a/test/TestPlayBook.py b/test/TestPlayBook.py index ebd8bd7aef9..85ee178fb1f 100644 --- a/test/TestPlayBook.py +++ b/test/TestPlayBook.py @@ -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 diff --git a/test/test_playbook_vars/group_vars/group b/test/test_playbook_vars/group_vars/group new file mode 100644 index 00000000000..6a07468c3bd --- /dev/null +++ b/test/test_playbook_vars/group_vars/group @@ -0,0 +1,2 @@ +--- +attr2: 2 diff --git a/test/test_playbook_vars/host_vars/host1 b/test/test_playbook_vars/host_vars/host1 new file mode 100644 index 00000000000..05a7ccaa5b6 --- /dev/null +++ b/test/test_playbook_vars/host_vars/host1 @@ -0,0 +1,2 @@ +--- +attr1: 1 diff --git a/test/test_playbook_vars/hosts b/test/test_playbook_vars/hosts new file mode 100644 index 00000000000..17ecaa85e6c --- /dev/null +++ b/test/test_playbook_vars/hosts @@ -0,0 +1,6 @@ +host1 +host2 + +[group] +host1 +host2 diff --git a/test/test_playbook_vars/playbook.yml b/test/test_playbook_vars/playbook.yml new file mode 100644 index 00000000000..7c3f03bfd09 --- /dev/null +++ b/test/test_playbook_vars/playbook.yml @@ -0,0 +1,2 @@ +--- +- hosts: group