diff --git a/.gitignore b/.gitignore index 7a508b0dd..ac5ec241d 100644 --- a/.gitignore +++ b/.gitignore @@ -76,3 +76,4 @@ playbooks/collections # Generated by bifrost-cli baremetal-inventory.json baremetal-nodes.json +bifrost-install-env.json diff --git a/bifrost/cli.py b/bifrost/cli.py index 5cb609268..3f6503201 100644 --- a/bifrost/cli.py +++ b/bifrost/cli.py @@ -15,6 +15,7 @@ import argparse import configparser import ipaddress import itertools +import json import os import subprocess import sys @@ -56,11 +57,20 @@ def process_extra_vars(extra_vars): def ansible(playbook, inventory, verbose=False, env=None, extra_vars=None, - **params): + params_output_file=None, **params): extra = COMMON_PARAMS[:] - extra.extend(itertools.chain.from_iterable( - ('-e', '%s=%s' % pair) for pair in params.items() - if pair[1] is not None)) + if params_output_file is None: + extra.extend(itertools.chain.from_iterable( + ('-e', '%s=%s' % pair) for pair in params.items() + if pair[1] is not None)) + else: + params_output_file = os.path.abspath(params_output_file) + log('Writing environment file', params_output_file, only_if=verbose) + with open(params_output_file, 'wt') as output: + json.dump({k: v for k, v in params.items() if v is not None}, + output) + extra.extend(['-e', '@%s' % params_output_file]) + if extra_vars: extra.extend(itertools.chain.from_iterable( process_extra_vars(extra_vars))) @@ -154,14 +164,14 @@ def cmd_install(args): ansible('install.yaml', inventory='inventory/target', verbose=args.debug, - create_ipa_image='false', - create_image_via_dib='false', - install_dib='true', + create_ipa_image=False, + create_image_via_dib=False, + install_dib=True, network_interface=args.network_interface, enable_keystone=args.enable_keystone, enable_tls=args.enable_tls, generate_tls=args.enable_tls, - noauth_mode='false', + noauth_mode=False, enabled_hardware_types=args.hardware_types, cleaning_disk_erase=args.cleaning_disk_erase, testing=args.testenv, @@ -172,6 +182,7 @@ def cmd_install(args): default_boot_mode=args.boot_mode or 'uefi', include_dhcp_server=not args.disable_dhcp, extra_vars=args.extra_vars, + params_output_file=args.output, **kwargs) log("Ironic is installed and running, try it yourself:\n", " $ source %s/bin/activate\n" % VENV, @@ -277,6 +288,10 @@ def parse_args(): help='Disable integrated dhcp server') install.add_argument('-e', '--extra-vars', action='append', help='additional vars to pass to ansible') + install.add_argument('-o', '--output', + default='baremetal-install-env.json', + help='output file with the ansible environment used ' + 'to install Bifrost (excluding -e arguments)') enroll = subparsers.add_parser( 'enroll', help='Enroll bare metal nodes') diff --git a/doc/source/install/index.rst b/doc/source/install/index.rst index 681042a19..f0533e165 100644 --- a/doc/source/install/index.rst +++ b/doc/source/install/index.rst @@ -295,6 +295,10 @@ See the built-in documentation for more details: ./bifrost-cli install --help +The Ansible variables generated for installation are stored in a JSON file +(``bifrost-install-env.json`` by default) that should be passed via the ``-e`` +flag to subsequent playbook or command invokations. + Using Bifrost ============= diff --git a/doc/source/user/howto.rst b/doc/source/user/howto.rst index 924503e92..fd40abe11 100644 --- a/doc/source/user/howto.rst +++ b/doc/source/user/howto.rst @@ -239,6 +239,16 @@ To utilize the newer dynamic inventory based deployment: cd playbooks ansible-playbook -vvvv -i inventory/bifrost_inventory.py deploy-dynamic.yaml +If you used ``bifrost-cli`` for installation, you should pass its environment +variables:: + + export BIFROST_INVENTORY_SOURCE=/tmp/baremetal.json + cd playbooks + ansible-playbook -vvvv \ + -i inventory/bifrost_inventory.py \ + -e @../bifrost-install-env.json \ + deploy-dynamic.yaml + .. note:: Before running the above command, ensure that the value for diff --git a/releasenotes/notes/bifrost-install-env-c424fe35422ca815.yaml b/releasenotes/notes/bifrost-install-env-c424fe35422ca815.yaml new file mode 100644 index 000000000..f832e0aef --- /dev/null +++ b/releasenotes/notes/bifrost-install-env-c424fe35422ca815.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The ``bifrost-cli install`` command now generates an environment file + (``bifrost-install-env.json`` by default, can be changed with the + ``--output`` argument) with the variables used during installation. diff --git a/scripts/collect-test-info.sh b/scripts/collect-test-info.sh index 1becd0100..d625da69c 100755 --- a/scripts/collect-test-info.sh +++ b/scripts/collect-test-info.sh @@ -86,6 +86,9 @@ ls -lR /httpboot > ${LOG_LOCATION}/pxe/listing.txt cp -aL /httpboot/*.ipxe ${LOG_LOCATION}/pxe/ cp -aL /httpboot/pxelinux.cfg/ ${LOG_LOCATION}/pxe/ +# Copy files generated by bifrost-cli +cp -a ${SCRIPT_HOME}/../playbooks/*.json ${LOG_LOCATION} + # Copy baremetal information source $HOME/openrc bifrost for vm in $(baremetal node list -c Name -f value); do