]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Refactor hosts file generation
authorZack Cerza <zack@redhat.com>
Tue, 23 Feb 2016 17:38:56 +0000 (10:38 -0700)
committerZack Cerza <zack@redhat.com>
Fri, 26 Feb 2016 17:01:45 +0000 (10:01 -0700)
This is in preparation to enable us to write host-specific vars to the
file.

Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/task/ceph_ansible.py

index 1da38ad39d106ab91c0405df5505f456e30d43e8..447149ba7f876b2c04f83bee067dc9882d5b847e 100644 (file)
@@ -79,16 +79,27 @@ class CephAnsible(ansible.Ansible):
             for (remote, roles) in self.cluster.only(want).remotes.iteritems():
                 hostname = remote.hostname
                 if group not in hosts_dict:
-                    hosts_dict[group] = [hostname]
+                    hosts_dict[group] = {hostname: None}
                 elif hostname not in hosts_dict[group]:
-                    hosts_dict[group].append(hostname)
+                    hosts_dict[group][hostname] = None
 
+        print hosts_dict
         hosts_stringio = StringIO()
         for group in sorted(hosts_dict.keys()):
-            hosts = hosts_dict[group]
             hosts_stringio.write('[%s]\n' % group)
-            hosts_stringio.write('\n'.join(hosts))
-            hosts_stringio.write('\n\n')
+            for hostname in sorted(hosts_dict[group].keys()):
+                vars = hosts_dict[group][hostname]
+                if vars:
+                    vars_list = ['%s=%s' % (k, v)
+                                 for k, v in vars.iteritems()]
+                    host_line = "{hostname} {vars}".format(
+                        hostname=hostname,
+                        vars=' '.join(vars_list),
+                    )
+                else:
+                    host_line = hostname
+                hosts_stringio.write('%s\n' % host_line)
+            hosts_stringio.write('\n')
         hosts_stringio.seek(0)
         self.inventory = self._write_hosts_file(hosts_stringio.read().strip())
         self.generated_inventory = True