Skip to content

Instantly share code, notes, and snippets.

@dginhoux
Last active November 8, 2022 22:21
Show Gist options
  • Save dginhoux/a84b8457a4cef762119fcc22f408a48e to your computer and use it in GitHub Desktop.
Save dginhoux/a84b8457a4cef762119fcc22f408a48e to your computer and use it in GitHub Desktop.
#!/bin/bash
export ANSIBLE_DIR="/mnt/gfs_lv_ansible"
export VENV_NAME="venv"
export VENV_DIR="$ANSIBLE_DIR/$VENV_NAME"
export PIP_LIST="ansible ansible-lint jinja2 jmespath yamllint"
export ACTION=$1
if [ "$ACTION" != 'install' ] && [ "$ACTION" != 'uninstall' ]; then
echo set action install or uninstall
exit 1
fi
if [ ! -f $VENV_DIR/bin/activate ]; then
python3 -m virtualenv --always-copy --clear $VENV_DIR
fi
if [ -f $VENV_DIR/bin/activate ]; then
source $VENV_DIR/bin/activate
if [ $? -eq 0 ] && [ $VIRTUAL_ENV == $VENV_DIR ]; then
python3 -m pip $ACTION --no-input --disable-pip-version-check --no-cache-dir $PIP_LIST
if [ "$ACTION" == 'install' ]; then
python3 -m pip freeze --local > $ANSIBLE_DIR/requirement_$VENV_NAME.txt
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment