Merge "Refactor setup_env.sh to use virtualenvs"

This commit is contained in:
Jenkins 2016-02-16 08:12:54 +00:00 committed by Gerrit Code Review
commit ab9554c77f
4 changed files with 18 additions and 50 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
venv/
infra_config.yml
openstack.py
inventory/openstack.py
.tox

View File

@ -1,8 +1,7 @@
Instructions
============
1. Run ``bash setup_env.sh``
2. Run ``source /opt/stack/ansible/hacking/env-setup``
1. Run ``source setup_env.sh``
3. Source your OpenStack cloud environment variables rc file
3. Run ``cp infra_config.yml.sample infra_config.yml``
4. Edit infra_config.yml and put your environment values

2
run.sh
View File

@ -1,3 +1,3 @@
#!/bin/bash
ansible-playbook -i hosts provision_infra_servers.yml -e "@infra_config.yml"
ansible-playbook -i /opt/stack/ansible/contrib/inventory/openstack.py site.yml -e "@infra_config.yml"
ansible-playbook -i inventory/openstack.py site.yml -e "@infra_config.yml"

View File

@ -1,53 +1,21 @@
#!/bin/bash
set -e
if [ -x '/usr/bin/apt-get' ]; then
if ! $(git --version &>/dev/null) ; then
sudo -H apt-get -y install git
fi
if ! $(pip -v &>/dev/null); then
sudo -H apt-get -y install python-pip
fi
elif [ -x '/usr/bin/yum' ]; then
if ! $(git --version &>/dev/null); then
sudo -H yum -y install git
fi
if ! $(pip -v &>/dev/null); then
sudo -H yum -y install python-pip
fi
else
echo "ERROR: Supported package manager not found. Supported: apt,yum"
# Install virtualenv package if not installed
if [ ! -f /usr/bin/pip ]; then
sudo -E apt-get install python-pip
fi
sudo -E pip install -r "$(dirname $0)/requirements.txt"
# Create infra-ansible virtual environment
pip install virtualenv
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
u=$(whoami)
g=$(groups | awk '{print $1}')
if [ ! -d /opt/stack ]; then
mkdir -p /opt/stack || (sudo mkdir -p /opt/stack)
fi
sudo -H chown -R $u:$g /opt/stack
cd /opt/stack
if [ ! -d ansible ]; then
git clone https://github.com/ansible/ansible.git --recursive
else
cd ansible
git checkout devel
git pull --rebase
git submodule update --init --recursive
git fetch
# Temporary direct checkout of devel due to broken modules until
# the submodules pointers get updated in the core ansible repo.
cd lib/ansible/modules/core
git checkout devel
# Create inventory folder
if [ ! -d inventory ]; then
mkdir inventory
fi
echo
echo "If your using this script directly, execute the"
echo "following commands to update your shell."
echo
echo "source env-vars"
echo "source /opt/stack/ansible/hacking/env-setup"
echo
# Install Ansible openstack inventory
/usr/bin/wget -N https://raw.githubusercontent.com/ansible/ansible/devel/contrib/inventory/openstack.py -O inventory/openstack.py
chmod +x inventory/openstack.py