diff --git a/scripts/bootstrap-aio.sh b/scripts/bootstrap-aio.sh index df778006c4..ac03ddc77c 100755 --- a/scripts/bootstrap-aio.sh +++ b/scripts/bootstrap-aio.sh @@ -25,8 +25,13 @@ export BOOTSTRAP_OPTS=${BOOTSTRAP_OPTS:-''} # Run AIO bootstrap playbook pushd tests - ansible-playbook -i test-inventory.ini \ - -e "${BOOTSTRAP_OPTS}" \ - bootstrap-aio.yml + if [ -z "${BOOTSTRAP_OPTS}" ]; then + ansible-playbook bootstrap-aio.yml \ + -i test-inventory.ini + else + ansible-playbook bootstrap-aio.yml \ + -i test-inventory.ini \ + -e "${BOOTSTRAP_OPTS}" + fi popd diff --git a/scripts/bootstrap-ansible.sh b/scripts/bootstrap-ansible.sh index 2af7f4f068..5b00198b43 100755 --- a/scripts/bootstrap-ansible.sh +++ b/scripts/bootstrap-ansible.sh @@ -41,6 +41,9 @@ info_block "Checking for required libraries." 2> /dev/null || ## Main ---------------------------------------------------------------------- info_block "Bootstrapping System with Ansible" +# Store the clone repo root location +export OSA_CLONE_DIR="$(pwd)" + # Set the variable to the role file to be the absolute path ANSIBLE_ROLE_FILE="$(readlink -f "${ANSIBLE_ROLE_FILE}")" @@ -106,32 +109,23 @@ ${PIP_COMMAND} install ${PIP_OPTS} ${PIP_INSTALL_OPTIONS} || ${PIP_COMMAND} inst # Install the required packages for ansible $PIP_COMMAND install $PIP_OPTS -r requirements.txt ${ANSIBLE_PACKAGE} || $PIP_COMMAND install --isolated $PIP_OPTS -r requirements.txt ${ANSIBLE_PACKAGE} -# Link the venv installation of Ansible to the local path -pushd /usr/local/bin - find /opt/ansible-runtime/bin/ -name 'ansible*' -exec ln -sf {} \; +# Ensure that Ansible binaries run from the venv +pushd /opt/ansible-runtime/bin + for ansible_bin in $(ls -1 ansible*); do + if [ "${ansible_bin}" == "ansible" ] || [ "${ansible_bin}" == "ansible-playbook" ]; then + + # For the 'ansible' and 'ansible-playbook' commands we want to use our wrapper + ln -sf /usr/local/bin/openstack-ansible /usr/local/bin/${ansible_bin} + + else + + # For any other commands, we want to link directly to the binary + ln -sf /opt/ansible-runtime/bin/${ansible_bin} /usr/local/bin/${ansible_bin} + + fi + done popd -# If the Ansible plugins are in the old location remove them. -[[ -d "/etc/ansible/plugins" ]] && rm -rf "/etc/ansible/plugins" - -# Update dependent roles -if [ -f "${ANSIBLE_ROLE_FILE}" ]; then - if [[ "${ANSIBLE_ROLE_FETCH_MODE}" == 'galaxy' ]];then - # Pull all required roles. - ansible-galaxy install --role-file="${ANSIBLE_ROLE_FILE}" \ - --force - elif [[ "${ANSIBLE_ROLE_FETCH_MODE}" == 'git-clone' ]];then - pushd tests - ansible-playbook -i "localhost ansible-connection=local," \ - get-ansible-role-requirements.yml \ - -e role_file="${ANSIBLE_ROLE_FILE}" - popd - else - echo "Please set the ANSIBLE_ROLE_FETCH_MODE to either of the following options ['galaxy', 'git-clone']" - exit 99 - fi -fi - # Copy the OSA Ansible rc file into place if [[ ! -f "/usr/local/bin/openstack-ansible.rc" ]]; then cp scripts/openstack-ansible.rc /usr/local/bin/openstack-ansible.rc @@ -161,21 +155,74 @@ cat > /usr/local/bin/openstack-ansible <<EOF export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}" function info() { - echo -e "\e[0;35m\${@}\e[0m" + if [ "\${ANSIBLE_NOCOLOR:-0}" -eq "1" ]; then + echo -e "\${@}" + else + echo -e "\e[0;35m\${@}\e[0m" + fi } -# Discover the variable files. -VAR1="\$(for i in \$(ls /etc/openstack_deploy/user_*.yml); do echo -ne "-e @\$i "; done)" +# Figure out which Ansible binary was executed +RUN_CMD=\$(basename \${0}) -# Provide information on the discovered variables. -info "Variable files: \"\${VAR1}\"" +# Apply the OpenStack-Ansible configuration selectively. +if [[ "\${PWD}" == *"${OSA_CLONE_DIR}"* ]] || [ "\${RUN_CMD}" == "openstack-ansible" ]; then -# Run the ansible playbook command. -. /usr/local/bin/openstack-ansible.rc && \$(which ansible-playbook) \${VAR1} \$@ + # Source the Ansible configuration. + . /usr/local/bin/openstack-ansible.rc + + # Check whether there are any user configuration files + if ls -1 /etc/openstack_deploy/user_*.yml &> /dev/null; then + + # Discover the variable files. + VAR1="\$(for i in \$(ls /etc/openstack_deploy/user_*.yml); do echo -ne "-e @\$i "; done)" + + # Provide information on the discovered variables. + info "Variable files: \"\${VAR1}\"" + + fi + +else + + # If you're not executing 'openstack-ansible' and are + # not in the OSA git clone root, then do not source + # the configuration and do not add extra vars. + VAR1="" + +fi + +# Execute the Ansible command. +if [ "\${RUN_CMD}" == "openstack-ansible" ] || [ "\${RUN_CMD}" == "ansible-playbook" ]; then + /opt/ansible-runtime/bin/ansible-playbook \${@} \${VAR1} +else + /opt/ansible-runtime/bin/\${RUN_CMD} "\${@}" +fi EOF # Ensure wrapper tool is executable chmod +x /usr/local/bin/openstack-ansible -echo "openstack-ansible script created." +echo "openstack-ansible wrapper created." + +# If the Ansible plugins are in the old location remove them. +[[ -d "/etc/ansible/plugins" ]] && rm -rf "/etc/ansible/plugins" + +# Update dependent roles +if [ -f "${ANSIBLE_ROLE_FILE}" ]; then + if [[ "${ANSIBLE_ROLE_FETCH_MODE}" == 'galaxy' ]];then + # Pull all required roles. + ansible-galaxy install --role-file="${ANSIBLE_ROLE_FILE}" \ + --force + elif [[ "${ANSIBLE_ROLE_FETCH_MODE}" == 'git-clone' ]];then + pushd tests + ansible-playbook get-ansible-role-requirements.yml \ + -i ${OSA_CLONE_DIR}/tests/test-inventory.ini \ + -e role_file="${ANSIBLE_ROLE_FILE}" + popd + else + echo "Please set the ANSIBLE_ROLE_FETCH_MODE to either of the following options ['galaxy', 'git-clone']" + exit 99 + fi +fi + echo "System is bootstrapped and ready for use." diff --git a/scripts/gate-check-commit.sh b/scripts/gate-check-commit.sh index 31310adf7e..bb22fa9bf4 100755 --- a/scripts/gate-check-commit.sh +++ b/scripts/gate-check-commit.sh @@ -72,10 +72,16 @@ iptables -P OUTPUT ACCEPT # Bootstrap an AIO pushd "$(dirname "${0}")/../tests" - ansible-playbook -i test-inventory.ini \ - -e "${BOOTSTRAP_OPTS}" \ - ${ANSIBLE_PARAMETERS} \ - bootstrap-aio.yml + if [ -z "${BOOTSTRAP_OPTS}" ]; then + ansible-playbook bootstrap-aio.yml \ + -i test-inventory.ini \ + ${ANSIBLE_PARAMETERS} + else + ansible-playbook bootstrap-aio.yml \ + -i test-inventory.ini \ + -e "${BOOTSTRAP_OPTS}" \ + ${ANSIBLE_PARAMETERS} + fi popd # Implement the log directory diff --git a/scripts/scripts-library.sh b/scripts/scripts-library.sh index 4d835b547a..d93316f177 100755 --- a/scripts/scripts-library.sh +++ b/scripts/scripts-library.sh @@ -82,7 +82,7 @@ function successerator { function install_bits { # Use the successerator to run openstack-ansible - successerator openstack-ansible ${ANSIBLE_PARAMETERS} $@ + successerator openstack-ansible $@ ${ANSIBLE_PARAMETERS} } function ssh_key_create {