Rework inventory repo based lcm

Also add docs

Change-Id: Ib2f3b57b979681b9bfcfa7a4e69b4d0609384f71
Signed-off-by: Bogdan Dobrelya <bdobrelia@mirantis.com>
This commit is contained in:
Bogdan Dobrelya 2016-08-26 12:45:45 +02:00
parent 317f3d46ca
commit 9d1f5a2856
3 changed files with 107 additions and 32 deletions

View File

@ -0,0 +1,24 @@
Fuel CCP installer
==================
Fuel CCP installer is a wrapper for a
`Kargo <https://github.com/kubespray/kargo>`_ installer.
It uses Ansible CM tool to install Kubernetes clusters.
It also provides some extra tools and playbooks.
Contents
~~~~~~~~
.. toctree::
:maxdepth: 2
host_requirements
inventory_repo
packer
collect_info
Search in this guide
~~~~~~~~~~~~~~~~~~~~
* :ref:`search`

View File

@ -0,0 +1,44 @@
Inventory and deployment data management
========================================
Deployment data and ansible inventory are represented as a git repository,
either remote or local. It is cloned and being updated on the admin node's
`$ADMIN_WORKSPACE/inventory` directory. The `$ADMIN_WORKSPACE` copies a value
of a given `$WORKSPACE` env var (defaults to the current directory of the
admin node). Or it takes a `workspace`, when the `$ADMIN_IP` refers to not a
`local` admin node. For example, if it is a VM.
Installer passes that data and inventory to
`Kargo <https://github.com/kubespray/kargo>`_ ansible installer.
For each inventory repo commit, it expects the following content of
the repo root directory:
* `inventory.cfg` - a mandatory inventory file. It must be created manually
or generated based on `$SLAVE_IPS` provided with the
`helper script <https://github.com/openstack/fuel-ccp-installer/blob/master/utils/kargo/inventory.py>`_.
* `kargo_default_common.yaml` - a mandatory vars file, overrides the kargo
defaults in the `$ADMIN_WORKSPACE/kargo/inventory/group_vars/all.yml`)
and defaults for roles.
* `kargo_default_ubuntu.yaml` - a mandatory vars file for Ubuntu nodes,
overrides the common file.
* `custom.yaml` - not a mandatory vars file, overrides all vars.
Note, that the `custom.yaml` make all data vars defined inside to override same
vars defined at other place. The data priority precedes as the following: kargo
defaults, then common defaults, then ubuntu defaults, then custom YAML.
Final data decisions is done automatically by the installer:
* If `$INVENTORY_REPO` is unset, make a local git repo and carry on and deploy.
* Or clone the given repo and checkout to `$INVENTORY_COMMIT`, if any.
* Copy installer defaults into the repo and decide on which data to accept:
* If a file changes, do git reset (shall not overwrite a commited state).
* If a new file, or has no changes, go with it (shall auto-populate defaults).
* Stage only new files, if any, then commit and run deployment with Kargo.
* If result is OK, submit changes as a gerrit review
* Or fail deployment, as we usually would, don't submit anything to gerrit.
Ongoing inventory changes must be submitted by a user to `$INVENTORY_REPO`
manually. Installer only initializes the repo during the initial install if it
is missing.

View File

@ -198,59 +198,66 @@ if [ -z "$INHERIT_SSH_AGENT" ]; then
admin_node_command chmod 600 .ssh/id_rsa
fi
# Try to get IPs from inventory if it isn't provided
# Use git repo if available, then residual files from previous deploy, then
# finally generate new inventory.
if [[ -n "$INVENTORY_REPO" ]]; then
# If no inventory repo, just make a local git repo and carry on and deploy.
# Otherwise, clone it and decide on the final deployment data.
if [ "${INVENTORY_REPO}" ]; then
admin_node_command "sh -c 'git clone $INVENTORY_REPO $ADMIN_WORKSPACE/inventory'" || true
if [[ -n "$INVENTORY_COMMIT" ]]; then
if [ -n "${INVENTORY_COMMIT}" ]; then
admin_node_command "sh -c 'cd $ADMIN_WORKSPACE/inventory && git fetch --all && git checkout $INVENTORY_COMMIT'"
fi
else
if [[ -z "$SLAVE_IPS" ]]; then
if admin_node_command stat $ADMIN_WORKSPACE/inventory/inventory.cfg; then
SLAVE_IPS=($(admin_node_command CONFIG_FILE=$ADMIN_WORKSPACE/inventory/inventory.cfg python3 $ADMIN_WORKSPACE/utils/kargo/inventory.py print_ips))
else
echo "No slave nodes available. Unable to proceed!"
exit_gracefully 1
fi
else
echo "Generating ansible inventory on admin node..."
admin_node_command mkdir -p $ADMIN_WORKSPACE/inventory
admin_node_command git init $ADMIN_WORKSPACE/inventory
admin_node_command CONFIG_FILE=$ADMIN_WORKSPACE/inventory/inventory.cfg python3 $ADMIN_WORKSPACE/utils/kargo/inventory.py ${SLAVE_IPS[@]}
if [ "${SLAVE_IPS}" -a -f $ADMIN_WORKSPACE/inventory/inventory.cfg ]; then
echo "ERROR: Updating inventory via SLAVE_IPS env var after initial deployment is not supported."
exit 1
fi
else
echo "Generating ansible inventory on admin node..."
admin_node_command mkdir -p $ADMIN_WORKSPACE/inventory
admin_node_command git init $ADMIN_WORKSPACE/inventory
fi
# TODO(mattymo): Compare timestamps to decide which default to use:
# git-based inventory or from fuel-ccp-installer
echo "Uploading default settings..."
echo "Uploading default settings and inventory..."
cat $COMMON_DEFAULTS_SRC | admin_node_command "cat > $ADMIN_WORKSPACE/inventory/${COMMON_DEFAULTS_YAML}"
cat $OS_SPECIFIC_DEFAULTS_SRC | admin_node_command "cat > $ADMIN_WORKSPACE/inventory/${OS_SPECIFIC_DEFAULTS_YAML}"
COMMON_DEFAULTS_OPT="-e @$ADMIN_WORKSPACE/inventory/${COMMON_DEFAULTS_YAML}"
OS_SPECIFIC_DEFAULTS_OPT="-e @$ADMIN_WORKSPACE/inventory/${OS_SPECIFIC_DEFAULTS_YAML}"
KARGO_DEFAULTS_OPT="-e @$ADMIN_WORKSPACE/kargo/inventory/group_vars/all.yml"
if [ -n "$CUSTOM_YAML" ]; then
if [ "${CUSTOM_YAML}" ]; then
echo "Uploading custom YAML for deployment..."
echo -e "$CUSTOM_YAML" | admin_node_command "cat > $ADMIN_WORKSPACE/inventory/custom.yaml"
custom_opts="-e @$ADMIN_WORKSPACE/inventory/custom.yaml"
fi
if [ "${SLAVE_IPS}" ]; then
admin_node_command CONFIG_FILE=$ADMIN_WORKSPACE/inventory/inventory.cfg python3 $ADMIN_WORKSPACE/utils/kargo/inventory.py ${SLAVE_IPS[@]}
fi
# Data committed to the inventory has the highest priority, then installer defaults
echo "Deciding on deployment data to the inventory repo..."
# Stage only new data files
admin_node_command "sh -c 'cd $ADMIN_WORKSPACE/inventory && git ls-files -o --exclude-standard | xargs -n1 git add'"
# Reset changed data files
admin_node_command "sh -c 'cd $ADMIN_WORKSPACE/inventory && git ls-files -m | xargs -n1 git checkout -- .'"
# Try to get IPs from inventory first
if [ -z "${SLAVE_IPS}" ]; then
if admin_node_command stat $ADMIN_WORKSPACE/inventory/inventory.cfg; then
SLAVE_IPS=($(admin_node_command CONFIG_FILE=$ADMIN_WORKSPACE/inventory/inventory.cfg python3 $ADMIN_WORKSPACE/utils/kargo/inventory.py print_ips))
else
echo "No slave nodes available. Unable to proceed!"
exit_gracefully 1
fi
fi
COMMON_DEFAULTS_OPT="-e @$ADMIN_WORKSPACE/inventory/${COMMON_DEFAULTS_YAML}"
OS_SPECIFIC_DEFAULTS_OPT="-e @$ADMIN_WORKSPACE/inventory/${OS_SPECIFIC_DEFAULTS_YAML}"
KARGO_DEFAULTS_OPT="-e @$ADMIN_WORKSPACE/kargo/inventory/group_vars/all.yml"
echo "Committing inventory changes..."
admin_node_command git -C $ADMIN_WORKSPACE/inventory add --all
if ! admin_node_command git config --get user.name; then
admin_node_command git config --global user.name "Anonymous User"
admin_node_command git config --global user.email "anon@example.org"
fi
# Commit only if there are changes
if ! admin_node_command git -C $ADMIN_WORKSPACE/inventory diff --exit-code; then
admin_node_command git -C $ADMIN_WORKSPACE/inventory git commit -a -m "Automated commit"
if ! admin_node_command git -C $ADMIN_WORKSPACE/inventory diff --cached --name-only --exit-code; then
admin_node_command "sh -c 'cd $ADMIN_WORKSPACE/inventory && git commit -a -m Automated\ commit'"
fi
echo "Waiting for all nodes to be reachable by SSH..."
wait_for_nodes ${SLAVE_IPS[@]}