diff --git a/deploy-guide/source/configure.rst b/deploy-guide/source/configure.rst index c38675aad2..5723d6cd81 100644 --- a/deploy-guide/source/configure.rst +++ b/deploy-guide/source/configure.rst @@ -57,6 +57,10 @@ For details about how the inventory is generated from the environment configuration, see `developer-inventory `_. +For details about how variable precedence works, and how to override +group vars, see +`developer-inventory-and-vars `_. + Installing additional services ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/source/developer-docs/index.rst b/doc/source/developer-docs/index.rst index 553fe36be4..9e2bd361a4 100644 --- a/doc/source/developer-docs/index.rst +++ b/doc/source/developer-docs/index.rst @@ -14,6 +14,7 @@ Contents: :maxdepth: 2 quickstart-aio + inventory-and-vars scripts contribute bug-triage diff --git a/doc/source/developer-docs/inventory-and-vars.rst b/doc/source/developer-docs/inventory-and-vars.rst new file mode 100644 index 0000000000..930278e369 --- /dev/null +++ b/doc/source/developer-docs/inventory-and-vars.rst @@ -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 diff --git a/playbooks/inventory/group_vars/all/all.yml b/group_vars/all/all.yml similarity index 100% rename from playbooks/inventory/group_vars/all/all.yml rename to group_vars/all/all.yml diff --git a/playbooks/inventory/group_vars/all/aodh.yml b/group_vars/all/aodh.yml similarity index 100% rename from playbooks/inventory/group_vars/all/aodh.yml rename to group_vars/all/aodh.yml diff --git a/playbooks/inventory/group_vars/all/ceilometer.yml b/group_vars/all/ceilometer.yml similarity index 100% rename from playbooks/inventory/group_vars/all/ceilometer.yml rename to group_vars/all/ceilometer.yml diff --git a/playbooks/inventory/group_vars/all/ceph.yml b/group_vars/all/ceph.yml similarity index 100% rename from playbooks/inventory/group_vars/all/ceph.yml rename to group_vars/all/ceph.yml diff --git a/playbooks/inventory/group_vars/all/cinder.yml b/group_vars/all/cinder.yml similarity index 100% rename from playbooks/inventory/group_vars/all/cinder.yml rename to group_vars/all/cinder.yml diff --git a/playbooks/inventory/group_vars/all/glance.yml b/group_vars/all/glance.yml similarity index 100% rename from playbooks/inventory/group_vars/all/glance.yml rename to group_vars/all/glance.yml diff --git a/playbooks/inventory/group_vars/all/haproxy.yml b/group_vars/all/haproxy.yml similarity index 100% rename from playbooks/inventory/group_vars/all/haproxy.yml rename to group_vars/all/haproxy.yml diff --git a/playbooks/inventory/group_vars/all/heat.yml b/group_vars/all/heat.yml similarity index 100% rename from playbooks/inventory/group_vars/all/heat.yml rename to group_vars/all/heat.yml diff --git a/playbooks/inventory/group_vars/all/infra.yml b/group_vars/all/infra.yml similarity index 100% rename from playbooks/inventory/group_vars/all/infra.yml rename to group_vars/all/infra.yml diff --git a/playbooks/inventory/group_vars/all/ironic.yml b/group_vars/all/ironic.yml similarity index 100% rename from playbooks/inventory/group_vars/all/ironic.yml rename to group_vars/all/ironic.yml diff --git a/playbooks/inventory/group_vars/all/keepalived.yml b/group_vars/all/keepalived.yml similarity index 100% rename from playbooks/inventory/group_vars/all/keepalived.yml rename to group_vars/all/keepalived.yml diff --git a/playbooks/inventory/group_vars/all/keystone.yml b/group_vars/all/keystone.yml similarity index 100% rename from playbooks/inventory/group_vars/all/keystone.yml rename to group_vars/all/keystone.yml diff --git a/playbooks/inventory/group_vars/all/magnum.yml b/group_vars/all/magnum.yml similarity index 100% rename from playbooks/inventory/group_vars/all/magnum.yml rename to group_vars/all/magnum.yml diff --git a/playbooks/inventory/group_vars/all/neutron.yml b/group_vars/all/neutron.yml similarity index 100% rename from playbooks/inventory/group_vars/all/neutron.yml rename to group_vars/all/neutron.yml diff --git a/playbooks/inventory/group_vars/all/nova.yml b/group_vars/all/nova.yml similarity index 100% rename from playbooks/inventory/group_vars/all/nova.yml rename to group_vars/all/nova.yml diff --git a/playbooks/inventory/group_vars/all/octavia.yml b/group_vars/all/octavia.yml similarity index 100% rename from playbooks/inventory/group_vars/all/octavia.yml rename to group_vars/all/octavia.yml diff --git a/playbooks/inventory/group_vars/all/pip.yml b/group_vars/all/pip.yml similarity index 100% rename from playbooks/inventory/group_vars/all/pip.yml rename to group_vars/all/pip.yml diff --git a/playbooks/inventory/group_vars/all/sahara.yml b/group_vars/all/sahara.yml similarity index 100% rename from playbooks/inventory/group_vars/all/sahara.yml rename to group_vars/all/sahara.yml diff --git a/playbooks/inventory/group_vars/all/ssl.yml b/group_vars/all/ssl.yml similarity index 100% rename from playbooks/inventory/group_vars/all/ssl.yml rename to group_vars/all/ssl.yml diff --git a/playbooks/inventory/group_vars/all/swift.yml b/group_vars/all/swift.yml similarity index 100% rename from playbooks/inventory/group_vars/all/swift.yml rename to group_vars/all/swift.yml diff --git a/playbooks/inventory/group_vars/all_containers.yml b/group_vars/all_containers.yml similarity index 100% rename from playbooks/inventory/group_vars/all_containers.yml rename to group_vars/all_containers.yml diff --git a/playbooks/inventory/group_vars/aodh_all.yml b/group_vars/aodh_all.yml similarity index 100% rename from playbooks/inventory/group_vars/aodh_all.yml rename to group_vars/aodh_all.yml diff --git a/playbooks/inventory/group_vars/barbican_all.yml b/group_vars/barbican_all.yml similarity index 100% rename from playbooks/inventory/group_vars/barbican_all.yml rename to group_vars/barbican_all.yml diff --git a/playbooks/inventory/group_vars/ceilometer_all.yml b/group_vars/ceilometer_all.yml similarity index 100% rename from playbooks/inventory/group_vars/ceilometer_all.yml rename to group_vars/ceilometer_all.yml diff --git a/playbooks/inventory/group_vars/ceph_all.yml b/group_vars/ceph_all.yml similarity index 100% rename from playbooks/inventory/group_vars/ceph_all.yml rename to group_vars/ceph_all.yml diff --git a/playbooks/inventory/group_vars/cinder_all.yml b/group_vars/cinder_all.yml similarity index 100% rename from playbooks/inventory/group_vars/cinder_all.yml rename to group_vars/cinder_all.yml diff --git a/playbooks/inventory/group_vars/cinder_volume.yml b/group_vars/cinder_volume.yml similarity index 100% rename from playbooks/inventory/group_vars/cinder_volume.yml rename to group_vars/cinder_volume.yml diff --git a/playbooks/inventory/group_vars/designate_all.yml b/group_vars/designate_all.yml similarity index 100% rename from playbooks/inventory/group_vars/designate_all.yml rename to group_vars/designate_all.yml diff --git a/playbooks/inventory/group_vars/galera_all.yml b/group_vars/galera_all.yml similarity index 100% rename from playbooks/inventory/group_vars/galera_all.yml rename to group_vars/galera_all.yml diff --git a/playbooks/inventory/group_vars/glance_all.yml b/group_vars/glance_all.yml similarity index 100% rename from playbooks/inventory/group_vars/glance_all.yml rename to group_vars/glance_all.yml diff --git a/playbooks/inventory/group_vars/gnocchi_all.yml b/group_vars/gnocchi_all.yml similarity index 100% rename from playbooks/inventory/group_vars/gnocchi_all.yml rename to group_vars/gnocchi_all.yml diff --git a/playbooks/inventory/group_vars/haproxy_all.yml b/group_vars/haproxy_all.yml similarity index 100% rename from playbooks/inventory/group_vars/haproxy_all.yml rename to group_vars/haproxy_all.yml diff --git a/playbooks/inventory/group_vars/heat_all.yml b/group_vars/heat_all.yml similarity index 100% rename from playbooks/inventory/group_vars/heat_all.yml rename to group_vars/heat_all.yml diff --git a/playbooks/inventory/group_vars/horizon_all.yml b/group_vars/horizon_all.yml similarity index 100% rename from playbooks/inventory/group_vars/horizon_all.yml rename to group_vars/horizon_all.yml diff --git a/playbooks/inventory/group_vars/hosts.yml b/group_vars/hosts.yml similarity index 100% rename from playbooks/inventory/group_vars/hosts.yml rename to group_vars/hosts.yml diff --git a/playbooks/inventory/group_vars/ironic_all.yml b/group_vars/ironic_all.yml similarity index 100% rename from playbooks/inventory/group_vars/ironic_all.yml rename to group_vars/ironic_all.yml diff --git a/playbooks/inventory/group_vars/ironic_compute.yml b/group_vars/ironic_compute.yml similarity index 100% rename from playbooks/inventory/group_vars/ironic_compute.yml rename to group_vars/ironic_compute.yml diff --git a/playbooks/inventory/group_vars/keystone_all.yml b/group_vars/keystone_all.yml similarity index 100% rename from playbooks/inventory/group_vars/keystone_all.yml rename to group_vars/keystone_all.yml diff --git a/playbooks/inventory/group_vars/magnum_all.yml b/group_vars/magnum_all.yml similarity index 100% rename from playbooks/inventory/group_vars/magnum_all.yml rename to group_vars/magnum_all.yml diff --git a/playbooks/inventory/group_vars/memcached.yml b/group_vars/memcached.yml similarity index 100% rename from playbooks/inventory/group_vars/memcached.yml rename to group_vars/memcached.yml diff --git a/playbooks/inventory/group_vars/neutron_agent.yml b/group_vars/neutron_agent.yml similarity index 100% rename from playbooks/inventory/group_vars/neutron_agent.yml rename to group_vars/neutron_agent.yml diff --git a/playbooks/inventory/group_vars/neutron_all.yml b/group_vars/neutron_all.yml similarity index 100% rename from playbooks/inventory/group_vars/neutron_all.yml rename to group_vars/neutron_all.yml diff --git a/playbooks/inventory/group_vars/neutron_calico_dhcp_agent.yml b/group_vars/neutron_calico_dhcp_agent.yml similarity index 100% rename from playbooks/inventory/group_vars/neutron_calico_dhcp_agent.yml rename to group_vars/neutron_calico_dhcp_agent.yml diff --git a/playbooks/inventory/group_vars/nova_all.yml b/group_vars/nova_all.yml similarity index 100% rename from playbooks/inventory/group_vars/nova_all.yml rename to group_vars/nova_all.yml diff --git a/playbooks/inventory/group_vars/octavia_all.yml b/group_vars/octavia_all.yml similarity index 100% rename from playbooks/inventory/group_vars/octavia_all.yml rename to group_vars/octavia_all.yml diff --git a/playbooks/inventory/group_vars/rabbitmq_all.yml b/group_vars/rabbitmq_all.yml similarity index 100% rename from playbooks/inventory/group_vars/rabbitmq_all.yml rename to group_vars/rabbitmq_all.yml diff --git a/playbooks/inventory/group_vars/repo_all.yml b/group_vars/repo_all.yml similarity index 100% rename from playbooks/inventory/group_vars/repo_all.yml rename to group_vars/repo_all.yml diff --git a/playbooks/inventory/group_vars/rsyslog.yml b/group_vars/rsyslog.yml similarity index 100% rename from playbooks/inventory/group_vars/rsyslog.yml rename to group_vars/rsyslog.yml diff --git a/playbooks/inventory/group_vars/sahara_all.yml b/group_vars/sahara_all.yml similarity index 100% rename from playbooks/inventory/group_vars/sahara_all.yml rename to group_vars/sahara_all.yml diff --git a/playbooks/inventory/group_vars/swift_all.yml b/group_vars/swift_all.yml similarity index 100% rename from playbooks/inventory/group_vars/swift_all.yml rename to group_vars/swift_all.yml diff --git a/playbooks/inventory/group_vars/trove_all.yml b/group_vars/trove_all.yml similarity index 100% rename from playbooks/inventory/group_vars/trove_all.yml rename to group_vars/trove_all.yml diff --git a/playbooks/inventory/group_vars/utility_all.yml b/group_vars/utility_all.yml similarity index 100% rename from playbooks/inventory/group_vars/utility_all.yml rename to group_vars/utility_all.yml diff --git a/playbooks/inventory/host_vars/localhost.yml b/host_vars/localhost.yml similarity index 100% rename from playbooks/inventory/host_vars/localhost.yml rename to host_vars/localhost.yml diff --git a/releasenotes/notes/group_vars_move-2e8f3c45935e98d8.yaml b/releasenotes/notes/group_vars_move-2e8f3c45935e98d8.yaml new file mode 100644 index 0000000000..f1b3f2f9b3 --- /dev/null +++ b/releasenotes/notes/group_vars_move-2e8f3c45935e98d8.yaml @@ -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. diff --git a/scripts/bootstrap-aio.sh b/scripts/bootstrap-aio.sh index ac03ddc77c..9ed9d5c23c 100755 --- a/scripts/bootstrap-aio.sh +++ b/scripts/bootstrap-aio.sh @@ -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 diff --git a/scripts/bootstrap-ansible.sh b/scripts/bootstrap-ansible.sh index 744132d134..558d0f8e67 100755 --- a/scripts/bootstrap-ansible.sh +++ b/scripts/bootstrap-ansible.sh @@ -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 diff --git a/scripts/gate-check-commit.sh b/scripts/gate-check-commit.sh index 5cb181bd4c..6d9034e354 100755 --- a/scripts/gate-check-commit.sh +++ b/scripts/gate-check-commit.sh @@ -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} diff --git a/scripts/openstack-ansible.rc b/scripts/openstack-ansible.rc index b5f3566b0c..97c057e28d 100644 --- a/scripts/openstack-ansible.rc +++ b/scripts/openstack-ansible.rc @@ -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/}" diff --git a/scripts/sources-branch-updater.sh b/scripts/sources-branch-updater.sh index 011078d329..cad2934977 100755 --- a/scripts/sources-branch-updater.sh +++ b/scripts/sources-branch-updater.sh @@ -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 diff --git a/scripts/update-revision.sh b/scripts/update-revision.sh index 385bdf734a..c725982701 100644 --- a/scripts/update-revision.sh +++ b/scripts/update-revision.sh @@ -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