From b1479e0f4c2ded50fc68a435b6271a5acbec10e4 Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Wed, 23 Mar 2016 14:59:18 -0300 Subject: Add --gen-inventory command to atomic-openshift-installer. This will just generate the Ansible inventory once all information is gathered, inform the user where to find it, and exit. Includes some test utility updates to make what broke as a result of this change less fragile. --- utils/src/ooinstall/cli_installer.py | 20 ++++++++++++++++---- utils/src/ooinstall/openshift_ansible.py | 3 +-- 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'utils/src/ooinstall') diff --git a/utils/src/ooinstall/cli_installer.py b/utils/src/ooinstall/cli_installer.py index c53ca7b18..b53545db2 100644 --- a/utils/src/ooinstall/cli_installer.py +++ b/utils/src/ooinstall/cli_installer.py @@ -837,8 +837,10 @@ def upgrade(ctx): @click.command() @click.option('--force', '-f', is_flag=True, default=False) +@click.option('--gen-inventory', is_flag=True, default=False, + help="Generate an ansible inventory file and exit.") @click.pass_context -def install(ctx, force): +def install(ctx, force, gen_inventory): oo_cfg = ctx.obj['oo_cfg'] verbose = ctx.obj['verbose'] @@ -861,7 +863,6 @@ def install(ctx, force): hosts_to_run_on, callback_facts = get_hosts_to_run_on( oo_cfg, callback_facts, ctx.obj['unattended'], force, verbose) - click.echo('Writing config to: %s' % oo_cfg.config_path) # We already verified this is not the case for unattended installs, so this can # only trigger for live CLI users: @@ -871,7 +872,18 @@ def install(ctx, force): if len(oo_cfg.calc_missing_facts()) > 0: confirm_hosts_facts(oo_cfg, callback_facts) + # Write quick installer config file to disk: oo_cfg.save_to_disk() + # Write ansible inventory file to disk: + inventory_file = openshift_ansible.generate_inventory(hosts_to_run_on) + + click.echo() + click.echo('Wrote atomic-openshift-installer config: %s' % oo_cfg.config_path) + click.echo("Wrote ansible inventory: %s" % inventory_file) + click.echo() + + if gen_inventory: + sys.exit(0) click.echo('Ready to run installation process.') message = """ @@ -880,8 +892,8 @@ If changes are needed please edit the config file above and re-run. if not ctx.obj['unattended']: confirm_continue(message) - error = openshift_ansible.run_main_playbook(oo_cfg.hosts, - hosts_to_run_on, verbose) + error = openshift_ansible.run_main_playbook(inventory_file, oo_cfg.hosts, + hosts_to_run_on, verbose) if error: # The bootstrap script will print out the log location. message = """ diff --git a/utils/src/ooinstall/openshift_ansible.py b/utils/src/ooinstall/openshift_ansible.py index 2b95702bf..edf8082fc 100644 --- a/utils/src/ooinstall/openshift_ansible.py +++ b/utils/src/ooinstall/openshift_ansible.py @@ -213,9 +213,8 @@ def default_facts(hosts, verbose=False): return load_system_facts(inventory_file, os_facts_path, facts_env, verbose) -def run_main_playbook(hosts, hosts_to_run_on, verbose=False): +def run_main_playbook(inventory_file, hosts, hosts_to_run_on, verbose=False): global CFG - inventory_file = generate_inventory(hosts_to_run_on) if len(hosts_to_run_on) != len(hosts): main_playbook_path = os.path.join(CFG.ansible_playbook_directory, 'playbooks/byo/openshift-node/scaleup.yml') -- cgit v1.2.3