Refactor setup_env.sh to use virtualenvs

Rather than relying on system-wide packages, just
create the virtualenv and leverage the already available
requirements.txt, which installs ansible along with other
dependencies.
Also pull the openstack inventory in the local inventory folder
as ansible pip package does not bundle the inventory utility.

Change-Id: I43b1c3fce522657854cdc20c55bd32366179b4b7
This commit is contained in:
Ricardo Carrillo Cruz 2016-02-15 12:43:06 +01:00
parent 44d6d10800
commit d902c16e19
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