Use root folder group_vars

Make sure the group_vars can be overriden by the deployer in
userspace.

This uses the vars_plugin to load all group_vars, to allow
key-based alphabetic merging of deployer overrides
from /etc/openstack_deploy.

Change-Id: I58aea2d2d3a1c872ae31ffe463a1ef4b553d9e17
This commit is contained in:
Jean-Philippe Evrard 2017-05-25 11:10:07 +00:00
parent 39900e1bcc
commit 58b4f6deb7
63 changed files with 86 additions and 12 deletions

View File

@ -57,6 +57,10 @@ For details about how the inventory is generated from the environment
configuration, see
`developer-inventory <http://docs.openstack.org/developer/openstack-ansible/developer-docs/inventory.html>`_.
For details about how variable precedence works, and how to override
group vars, see
`developer-inventory-and-vars <http://docs.openstack.org/developer/openstack-ansible/developer-docs/inventory-and-vars.html>`_.
Installing additional services
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -14,6 +14,7 @@ Contents:
:maxdepth: 2
quickstart-aio
inventory-and-vars
scripts
contribute
bug-triage

View File

@ -0,0 +1,51 @@
=======================
Inventory and variables
=======================
Our dynamic Inventory
^^^^^^^^^^^^^^^^^^^^^
OpenStack-Ansible ships with its own dynamic inventory. You can
find more explanations on the `inventory`_.
Variable precedence
^^^^^^^^^^^^^^^^^^^
Role defaults
-------------
Every role has a file, ``defaults/main.yml`` which holds the
usual variables overridable by a deployer, like a regular Ansible
role. This defaults are the closest possible to OpenStack standards.
Group vars and host vars
------------------------
OpenStack-Ansible provides safe defaults for deployers in its
group_vars folder. They take care of the wiring between different
roles, like for example storing information on how to reach
RabbitMQ from nova role.
You can override the existing group vars (and host vars) by creating
your own folder in /etc/openstack_deploy/group_vars (and
/etc/openstack_deploy/host_vars respectively).
If you want to change the location of the override folder, you
can adapt your openstack-ansible.rc file, or export
``GROUP_VARS_PATH`` and ``HOST_VARS_PATH`` during your shell session.
Role vars
---------
Because OpenStack-Ansible is following Ansible precedence, every role
``vars/`` will take precedence over group vars. This is intentional.
You should avoid overriding these variables.
User variables
--------------
If you want to override a playbook or a role variable, you can define
the variable you want to override in a
``/etc/openstack_deploy/user_*.yml`` file.
.. _Inventory: inventory.html

View File

@ -0,0 +1,9 @@
---
features:
- |
From now on, a deployer can override any group_var in userspace, by
creating a folder ``/etc/openstack_deploy/group_vars/``. This folder
has precedence over OpenStack-Ansible default group_vars, and the
merge behavior is similar to Ansible merge behavior.
The group_vars folder precedence can still be changed with the
GROUP_VARS_PATH. Same applies for host vars.

View File

@ -24,12 +24,16 @@ export BOOTSTRAP_OPTS=${BOOTSTRAP_OPTS:-''}
## Main ----------------------------------------------------------------------
# Run AIO bootstrap playbook
unset ANSIBLE_VARS_PLUGINS
unset HOST_VARS_PATH
unset GROUP_VARS_PATH
pushd tests
if [ -z "${BOOTSTRAP_OPTS}" ]; then
ansible-playbook bootstrap-aio.yml \
/opt/ansible-runtime/bin/ansible-playbook bootstrap-aio.yml \
-i test-inventory.ini
else
ansible-playbook bootstrap-aio.yml \
/opt/ansible-runtime/bin/ansible-playbook bootstrap-aio.yml \
-i test-inventory.ini \
-e "${BOOTSTRAP_OPTS}"
fi

View File

@ -143,6 +143,8 @@ popd
# Write the OSA Ansible rc file
sed "s|OSA_INVENTORY_PATH|${OSA_INVENTORY_PATH}|g" scripts/openstack-ansible.rc > /usr/local/bin/openstack-ansible.rc
sed -i "s|OSA_GROUP_VARS_DIR|${OSA_CLONE_DIR}/group_vars/|g" /usr/local/bin/openstack-ansible.rc
sed -i "s|OSA_HOST_VARS_DIR|${OSA_CLONE_DIR}/host_vars/|g" /usr/local/bin/openstack-ansible.rc
# Create openstack ansible wrapper tool

View File

@ -127,13 +127,17 @@ iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
# Bootstrap an AIO
unset ANSIBLE_VARS_PLUGINS
unset HOST_VARS_PATH
unset GROUP_VARS_PATH
pushd "$(dirname "${0}")/../tests"
if [ -z "${BOOTSTRAP_OPTS}" ]; then
ansible-playbook bootstrap-aio.yml \
/opt/ansible-runtime/bin/ansible-playbook bootstrap-aio.yml \
-i test-inventory.ini \
${ANSIBLE_PARAMETERS}
else
ansible-playbook bootstrap-aio.yml \
/opt/ansible-runtime/bin/ansible-playbook bootstrap-aio.yml \
-i test-inventory.ini \
-e "${BOOTSTRAP_OPTS}" \
${ANSIBLE_PARAMETERS}

View File

@ -56,5 +56,5 @@ export ANSIBLE_FORCE_HANDLERS="${ANSIBLE_FORCE_HANDLERS:-True}"
# Allow the usage of userspace group_vars host_vars with user
# defined precedence until this behavior is merged in the
# inventory
export GROUP_VARS_PATH="${GROUP_VARS_PATH:-/etc/openstack_deploy/group_vars/}"
export HOST_VARS_PATH="${HOST_VARS_PATH:-/etc/openstack_deploy/host_vars/}"
export GROUP_VARS_PATH="${GROUP_VARS_PATH:-OSA_GROUP_VARS_DIR:/etc/openstack_deploy/group_vars/}"
export HOST_VARS_PATH="${HOST_VARS_PATH:-OSA_HOST_VARS_DIR:/etc/openstack_deploy/host_vars/}"

View File

@ -197,7 +197,7 @@ sed -i.bak "s|^PIP_INSTALL_OPTIONS=.*|PIP_INSTALL_OPTIONS=\$\{PIP_INSTALL_OPTION
for pin in ${PIP_CURRENT_OPTIONS}; do
sed -i.bak "s|^$(echo ${pin} | cut -f1 -d=).*|${pin}|" global-requirement-pins.txt
sed -i.bak "s|^ - $(echo ${pin} | cut -f1 -d=).*| - ${pin}|" playbooks/inventory/group_vars/all/pip.yml
sed -i.bak "s|^ - $(echo ${pin} | cut -f1 -d=).*| - ${pin}|" group_vars/all/pip.yml
done
echo "Updated pip install options/pins"
@ -263,13 +263,13 @@ else
echo "Skipping the ansible-role-requirements.yml update as we're working on the master branch"
fi
# Update the release version in playbooks/inventory/group_vars/all/all.yml
# Update the release version in group_vars/all/all.yml
# We don't want to be doing this for the master branch and we only want
# to do it once, so we key off of a specific repo source file name.
if [[ "${OSA_BRANCH}" != "master" ]] && [[ "${SERVICE_FILE}" == "playbooks/defaults/repo_packages/openstack_services.yml" ]]; then
echo "Updating the release version..."
currentversion=$(awk '/openstack_release:/ {print $2}' playbooks/inventory/group_vars/all/all.yml)
currentversion=$(awk '/openstack_release:/ {print $2}' group_vars/all/all.yml)
# Extract the required version info
major_version=$( echo ${currentversion} | cut -d. -f1 )
@ -279,7 +279,7 @@ if [[ "${OSA_BRANCH}" != "master" ]] && [[ "${SERVICE_FILE}" == "playbooks/defau
# increment the patch version
patch_version=$(( patch_version + 1 ))
sed -i .bak "s/${currentversion}/${major_version}.${minor_version}.${patch_version}/" playbooks/inventory/group_vars/all/all.yml
sed -i .bak "s/${currentversion}/${major_version}.${minor_version}.${patch_version}/" group_vars/all/all.yml
else
echo "Skipping the release version update as we're working on the master branch"
fi

View File

@ -40,5 +40,4 @@ esac
shift
done
sed -i.bak "s/^openstack_release\:.*/openstack_release\: ${REVISION}/" playbooks/inventory/group_vars/all/all.yml
sed -i.bak "s/^openstack_release\:.*/openstack_release\: ${REVISION}/" group_vars/all/all.yml