Put variables into the inventory
Instead of using a vars.yaml file and a -e command, just put the
variables into the all group in the inventory file. One less file to
manage, single file to look at for debugging.
Change-Id: I5b1f149ecca649b1434488392cc8232de20cd4fc
diff --git a/tests/unit/test_inventory.py b/tests/unit/test_inventory.py
index dca2e7e..2835d30 100644
--- a/tests/unit/test_inventory.py
+++ b/tests/unit/test_inventory.py
@@ -44,8 +44,15 @@
all_nodes = ('ubuntu-xenial',)
self.assertIn('all', inventory)
self.assertIn('hosts', inventory['all'])
+ self.assertIn('vars', inventory['all'])
for node_name in all_nodes:
self.assertIn(node_name, inventory['all']['hosts'])
+ self.assertIn('zuul', inventory['all']['vars'])
+ z_vars = inventory['all']['vars']['zuul']
+ self.assertIn('executor', z_vars)
+ self.assertIn('src_root', z_vars['executor'])
+ self.assertIn('job', z_vars)
+ self.assertEqual(z_vars['job'], 'single-inventory')
self.executor_server.release()
self.waitUntilSettled()
@@ -57,11 +64,19 @@
all_nodes = ('controller', 'compute1', 'compute2')
self.assertIn('all', inventory)
self.assertIn('hosts', inventory['all'])
+ self.assertIn('vars', inventory['all'])
for group_name in ('ceph-osd', 'ceph-monitor'):
self.assertIn(group_name, inventory)
for node_name in all_nodes:
self.assertIn(node_name, inventory['all']['hosts'])
self.assertIn(node_name,
inventory['ceph-monitor']['hosts'])
+ self.assertIn('zuul', inventory['all']['vars'])
+ z_vars = inventory['all']['vars']['zuul']
+ self.assertIn('executor', z_vars)
+ self.assertIn('src_root', z_vars['executor'])
+ self.assertIn('job', z_vars)
+ self.assertEqual(z_vars['job'], 'group-inventory')
+
self.executor_server.release()
self.waitUntilSettled()
diff --git a/zuul/executor/server.py b/zuul/executor/server.py
index f88af53..2b67f95 100644
--- a/zuul/executor/server.py
+++ b/zuul/executor/server.py
@@ -184,7 +184,6 @@
os.makedirs(self.ansible_root)
self.known_hosts = os.path.join(self.ansible_root, 'known_hosts')
self.inventory = os.path.join(self.ansible_root, 'inventory.yaml')
- self.vars = os.path.join(self.ansible_root, 'vars.yaml')
self.playbooks = [] # The list of candidate playbooks
self.playbook = None # A pointer to the candidate we have chosen
self.pre_playbooks = []
@@ -313,7 +312,7 @@
shutil.copy(os.path.join(library_path, fn), target_dir)
-def make_inventory_dict(nodes, groups):
+def make_inventory_dict(nodes, groups, all_vars):
hosts = {}
for node in nodes:
@@ -322,6 +321,7 @@
inventory = {
'all': {
'hosts': hosts,
+ 'vars': all_vars,
}
}
@@ -1103,8 +1103,14 @@
self.jobdir.trusted_roles_path.append(trusted_role_path)
def prepareAnsibleFiles(self, args):
+ all_vars = dict(args['vars'])
+ all_vars['zuul']['executor'] = dict(
+ hostname=self.executor_server.hostname,
+ src_root=self.jobdir.src_root,
+ log_root=self.jobdir.log_root)
+
nodes = self.getHostList(args)
- inventory = make_inventory_dict(nodes, args['groups'])
+ inventory = make_inventory_dict(nodes, args['groups'], all_vars)
with open(self.jobdir.inventory, 'w') as inventory_yaml:
inventory_yaml.write(
@@ -1115,14 +1121,6 @@
for key in node['host_keys']:
known_hosts.write('%s\n' % key)
- with open(self.jobdir.vars, 'w') as vars_yaml:
- zuul_vars = dict(args['vars'])
- zuul_vars['zuul']['executor'] = dict(
- hostname=self.executor_server.hostname,
- src_root=self.jobdir.src_root,
- log_root=self.jobdir.log_root)
- vars_yaml.write(
- yaml.safe_dump(zuul_vars, default_flow_style=False))
self.writeAnsibleConfig(self.jobdir.untrusted_config)
self.writeAnsibleConfig(self.jobdir.trusted_config, trusted=True)
@@ -1276,12 +1274,10 @@
else:
verbose = '-v'
- cmd = ['ansible-playbook', playbook.path]
+ cmd = ['ansible-playbook', verbose, playbook.path]
if success is not None:
cmd.extend(['-e', 'success=%s' % str(bool(success))])
- cmd.extend(['-e@%s' % self.jobdir.vars, verbose])
-
return self.runAnsible(
cmd=cmd, timeout=timeout, trusted=playbook.trusted)