Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/bin/sh
- #########################
- # VARS
- #########################
- ANSIBLE_DEFAULT_VERSION="2.5.4"
- ANSIBLE_EXTRA_VERSIONS="2.6.0 2.6.5 2.7.0 2.7.7"
- PIP_REQUIREMENT="ansible-lint shade python-openstackclient"
- SYSTEM_REQUIREMENTS="python2.7 python3 python3.5 python-pip python3-pip python3-virtualenv"
- #########################
- # MAIN
- #########################
- ANSIBLE_VERSION=$ANSIBLE_DEFAULT_VERSION" "$ANSIBLE_EXTRA_VERSIONS
- echo -e "\nWelcome to the ansible environment installer\n===================================================="
- echo -e "\nMaking sure system requirements are in order\n--------------------------------------------"
- sudo apt-get install ${SYSTEM_REQUIREMENTS}
- echo -e "\nChecking virtualenv base dir exists\n-----------------------------------"
- mkdir -p ~/.venv
- echo -e "\nChecking bashrc ansible entries\n-------------------------------"
- grep -qxF "[ -f ~/.venv/ansible.bash ] && source ~/.venv/ansible.bash" ~/.bashrc 2>/dev/null || echo "[ -f ~/.venv/ansible.bash ] && source ~/.venv/ansible.bash" >> ~/.bashrc
- grep -qxF "[ -f ~/.venv/ansible/bin/activate ] && source ~/.venv/ansible/bin/activate ; ansible --version" ~/.bashrc 2>/dev/null || echo "[ -f ~/.venv/ansible/bin/activate ] && source ~/.venv/ansible/bin/activate ; ansible --version" >> ~/.bashrc
- echo -e "\nMaking sure ansible virtualenv alias script is up to date\n---------------------------------------------------------"
- echo "" > ~/.venv/ansible.bash
- cat <<\EOF >> ~/.venv/ansible.bash
- for v in $(find ~/.venv/ -mindepth 1 -maxdepth 1 2>/dev/null);
- do
- if [ -f ${v}/bin/activate ]; then
- alias v-$(basename ${v})="source ${v}/bin/activate ; if [[ $(basename ${v}) =~ ansible.* ]]; then ansible --version ;fi"
- fi
- done
- EOF
- for version in ${ANSIBLE_VERSION}
- do
- cd ~/.venv/
- echo -e "\nMaking sure ansible ${version} is installed\n--------------------------------------" |tee -a ~/.venv/install.log
- mkdir -p ansible_${version}
- virtualenv -p python3 ansible_${version} 2>&1 |tee -a ~/.venv/install.log
- source ansible_${version}/bin/activate
- pip install ansible==${version} ${PIP_REQUIREMENT} 2>> ~/.venv/install.log 1>> ~/.venv/install.log
- deactivate
- if [[ "${version}" == "${ANSIBLE_DEFAULT_VERSION}" ]]; then
- rm -f ansible
- ln -s ansible_${version} ansible
- fi
- done
- echo -e "\n\nAll done, enjoy automation!\n==========================="
- echo -e "any changes will become active when you reload .bashrc (. ~/.bashrc) or start a new terminal\n"
- # exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement