Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #/bin/sh
  2.  
  3. #########################
  4. # VARS
  5. #########################
  6. ANSIBLE_DEFAULT_VERSION="2.5.4"
  7. ANSIBLE_EXTRA_VERSIONS="2.6.0 2.6.5 2.7.0 2.7.7"
  8.  
  9. PIP_REQUIREMENT="ansible-lint shade python-openstackclient"
  10. SYSTEM_REQUIREMENTS="python2.7 python3 python3.5 python-pip python3-pip python3-virtualenv"
  11.  
  12. #########################
  13. # MAIN
  14. #########################
  15. ANSIBLE_VERSION=$ANSIBLE_DEFAULT_VERSION" "$ANSIBLE_EXTRA_VERSIONS
  16.  
  17. echo -e "\nWelcome to the ansible environment installer\n===================================================="
  18.  
  19. echo -e "\nMaking sure system requirements are in order\n--------------------------------------------"
  20. sudo apt-get install ${SYSTEM_REQUIREMENTS}
  21.  
  22. echo -e "\nChecking virtualenv base dir exists\n-----------------------------------"
  23. mkdir -p ~/.venv
  24.  
  25. echo -e "\nChecking bashrc ansible entries\n-------------------------------"
  26. grep -qxF "[ -f ~/.venv/ansible.bash ] && source ~/.venv/ansible.bash" ~/.bashrc 2>/dev/null || echo "[ -f ~/.venv/ansible.bash ] && source ~/.venv/ansible.bash" >> ~/.bashrc
  27. 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
  28.  
  29. echo -e "\nMaking sure ansible virtualenv alias script is up to date\n---------------------------------------------------------"
  30. echo "" > ~/.venv/ansible.bash
  31. cat <<\EOF >> ~/.venv/ansible.bash
  32. for v in $(find ~/.venv/ -mindepth 1 -maxdepth 1 2>/dev/null);
  33. do
  34. if [ -f ${v}/bin/activate ]; then
  35. alias v-$(basename ${v})="source ${v}/bin/activate ; if [[ $(basename ${v}) =~ ansible.* ]]; then ansible --version ;fi"
  36. fi
  37. done
  38. EOF
  39.  
  40. for version in ${ANSIBLE_VERSION}
  41. do
  42. cd ~/.venv/
  43. echo -e "\nMaking sure ansible ${version} is installed\n--------------------------------------" |tee -a ~/.venv/install.log
  44. mkdir -p ansible_${version}
  45. virtualenv -p python3 ansible_${version} 2>&1 |tee -a ~/.venv/install.log
  46. source ansible_${version}/bin/activate
  47. pip install ansible==${version} ${PIP_REQUIREMENT} 2>> ~/.venv/install.log 1>> ~/.venv/install.log
  48. deactivate
  49. if [[ "${version}" == "${ANSIBLE_DEFAULT_VERSION}" ]]; then
  50. rm -f ansible
  51. ln -s ansible_${version} ansible
  52. fi
  53. done
  54.  
  55. echo -e "\n\nAll done, enjoy automation!\n==========================="
  56. echo -e "any changes will become active when you reload .bashrc (. ~/.bashrc) or start a new terminal\n"
  57.  
  58. # exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement