Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always load group_vars and host_vars. #865

Merged
merged 1 commit into from
Aug 14, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions lib/ansible/playbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ def _do_setup_step(self, play):
# 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

Expand All @@ -299,14 +298,12 @@ def _run_play(self, play):
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:
Expand All @@ -323,4 +320,3 @@ def _run_play(self, play):
self.inventory.restrict_to(handler.notified_by)
self._run_task(play, handler, True)
self.inventory.lift_restriction()

19 changes: 13 additions & 6 deletions test/TestPlayBook.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ def set_playbook(self, playbook):
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 ]])

Expand All @@ -46,9 +43,6 @@ def on_notify(self, host, handler):
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 ]])

Expand Down Expand Up @@ -161,6 +155,19 @@ def test_one(self):
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
Expand Down
2 changes: 2 additions & 0 deletions test/test_playbook_vars/group_vars/group
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
attr2: 2
2 changes: 2 additions & 0 deletions test/test_playbook_vars/host_vars/host1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
attr1: 1
6 changes: 6 additions & 0 deletions test/test_playbook_vars/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
host1
host2

[group]
host1
host2
2 changes: 2 additions & 0 deletions test/test_playbook_vars/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
- hosts: group