autocluster: Factor out construction of generated config file name
authorMartin Schwenke <martin@meltin.net>
Tue, 8 Oct 2019 04:48:45 +0000 (15:48 +1100)
committerMartin Schwenke <martin@meltin.net>
Tue, 8 Oct 2019 05:39:00 +0000 (16:39 +1100)
Signed-off-by: Martin Schwenke <martin@meltin.net>
autocluster.py

index 78824caa876914b1b3745e93792ade074f29a17b..985979ba1073688d20a8fe73ec4ab21db964c1ab 100755 (executable)
@@ -343,10 +343,10 @@ def load_config(cluster):
     return out
 
 
-def generate_config_yml(config, outdir):
+def generate_config_yml(cluster, config):
     '''Output combined YAML configuration to "config.yml"'''
 
-    outfile = os.path.join(outdir, 'config.yml')
+    outfile = get_config_file_path(cluster)
 
     with open(outfile, 'w') as stream:
         out = yaml.dump(config, default_flow_style=False)
@@ -449,6 +449,12 @@ def get_state_dir(cluster):
     return os.path.join(os.getcwd(), '.autocluster', cluster)
 
 
+def get_config_file_path(cluster):
+    '''Return the name of the generated config file for cluster'''
+
+    return os.path.join(get_state_dir(cluster), 'config.yml')
+
+
 def announce(group, cluster, command):
     '''Print a banner announcing the current step'''
 
@@ -473,7 +479,7 @@ def cluster_generate(cluster):
         if err.errno != errno.EEXIST:
             raise
 
-    generate_config_yml(config, outdir)
+    generate_config_yml(cluster, config)
     generate_hosts(cluster, config, outdir)
     generate_ssh_config(config, outdir)
     generate_ansible_inventory(config, outdir)
@@ -658,7 +664,7 @@ def cluster_setup(cluster):
     os.environ['ANSIBLE_RETRY_FILES_ENABLED'] = 'false'
 
     state_dir = get_state_dir(cluster)
-    config_file = os.path.join(state_dir, 'config.yml')
+    config_file = get_config_file_path(cluster)
     inventory = os.path.join(state_dir, 'ansible.inventory')
     playbook = os.path.join(INSTALL_DIR, 'ansible/node/site.yml')
     args = ['ansible-playbook',