Generate an environment file during bifrost-cli install

It is recommended to pass the same variables (e.g. testing) to other
commands and playbooks, the new file makes it possible.

Change-Id: I2adc4e2dcfd8555b2c9e6c3bf0f512f603367091
This commit is contained in:
Dmitry Tantsur 2022-01-06 11:49:32 +01:00
parent 40842895fc
commit 9b83665d83
6 changed files with 47 additions and 8 deletions

1
.gitignore vendored
View File

@ -76,3 +76,4 @@ playbooks/collections
# Generated by bifrost-cli
baremetal-inventory.json
baremetal-nodes.json
bifrost-install-env.json

View File

@ -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')

View File

@ -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
=============

View File

@ -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

View File

@ -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.

View File

@ -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