mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Always load group_vars and host_vars.
This commit is contained in:
parent
7ab0d60b1a
commit
b42e835aab
6 changed files with 27 additions and 12 deletions
|
@ -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))
|
||||
|
||||
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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
2
test/test_playbook_vars/group_vars/group
Normal file
2
test/test_playbook_vars/group_vars/group
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
attr2: 2
|
2
test/test_playbook_vars/host_vars/host1
Normal file
2
test/test_playbook_vars/host_vars/host1
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
attr1: 1
|
6
test/test_playbook_vars/hosts
Normal file
6
test/test_playbook_vars/hosts
Normal file
|
@ -0,0 +1,6 @@
|
|||
host1
|
||||
host2
|
||||
|
||||
[group]
|
||||
host1
|
||||
host2
|
2
test/test_playbook_vars/playbook.yml
Normal file
2
test/test_playbook_vars/playbook.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- hosts: group
|
Loading…
Reference in a new issue