-
Notifications
You must be signed in to change notification settings - Fork 1
/
environment.sh
53 lines (43 loc) · 1.43 KB
/
environment.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /bin/bash
export ANS_ROOT_DIR="$(readlink -m $(readlink -m "$(dirname "${BASH_SOURCE[0]}")"))"
export EC2_INI_PATH=$ANS_ROOT_DIR/etc/inv/ec2.ini
#export ANSIBLE_VAULT_PASSWORD_FILE=~/.ssh/vault_pass_11.txt
#export ANSIBLE_SSH_CONTROL_PATH="/tmp/ansible-ssh-$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c8)-%%h-%%p-%%r"
export ANSIBLE_CONFIG="$(pwd)/ansible.cfg"
#export ANSIBLE_KEEP_REMOTE_FILES=1
while getopts ":i" __optarg; do
case "$__optarg" in
i)
__install_requirements=true
;;
esac
done
if [ -z "$VIRTUAL_ENV" ]; then
if ! [ -d $ANS_ROOT_DIR/venv ]; then
echo '-- No virtualenv detected; creating'
virtualenv $ANS_ROOT_DIR/venv || (echo '!!! virtualenv creation failed' && return)
mkdir ~/.ansible
mkdir ~/facts_cache
touch ~/.ssh/secure_located_file
__venv_created=true
fi
source $ANS_ROOT_DIR/venv/bin/activate
fi
if [ "$__venv_created" = true ] || [ "$__install_requirements" = true ]; then
echo '-- Installing requirements'
pip install -r $ANS_ROOT_DIR/requirements.txt || (echo '!!! pip install failed' && return)
fi
if ! declare -f __old_deactivate 2>&1 > /dev/null; then
__old_deactivate_source=$(declare -f deactivate)
eval "__old_deactivate${__old_deactivate_source#deactivate}"
function deactivate {
__old_deactivate
unset ANS_ROOT_DIR
unset EC2_INI_PATH
unset __old_deactivate
}
fi
unset OPTIND
unset __optarg
unset __venv_created
unset __install_requirements