Last active
June 5, 2017 12:03
-
-
Save shrikeh/7773030d8b237ea3b7c5baab2652d927 to your computer and use it in GitHub Desktop.
CentOS 6 Python bootstrap, necessary for Packer and Vagrant if you wish to provision with Python-based provisioners such as Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
function bootstrap_python() { | |
local PYTHON_PROFILE_PATH='/etc/profile.d/python2.7.sh'; | |
local CACHE_PYTHON_PROFILE=true; | |
local CACHE_PYTHON_PROFILE_PATH='/vagrant/.vagrant/cache/python2.7.sh'; | |
# To save doing this on every provision, check if the file already exists. | |
if [ -e "${PYTHON_PROFILE_PATH}" ] ; then | |
echo "Profile found at ${PYTHON_PROFILE_PATH}, skipping setup"; | |
return 0; | |
fi | |
echo 'Upgrading packages...'; | |
yum upgrade -y; | |
echo 'Installing development tools, OpenSSL, etc...' | |
yum groupinstall -y 'Development tools' || return 1; | |
yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget || return 1; | |
echo 'Installing CentOS SCL...'; | |
yum install -y centos-release-scl; | |
# While the libselinux-python isn't strictly necessary, the number of times I smack into this | |
# building *anything* with Ansible means I include it here. | |
echo 'Installing Python 2.7...'; | |
yum install -y python27 libselinux-python || return 1; | |
echo 'Cleaning up...'; | |
yum clean all 2>&1 >/dev/null; | |
echo "Adding Python 2.7 to global profile at ${PYTHON_PROFILE_PATH}"; | |
if [ "${CACHE_PYTHON_PROFILE}" = true ]; then | |
if [ -e "${CACHE_PYTHON_PROFILE_PATH}" ]; then | |
cp "${CACHE_PYTHON_PROFILE_PATH}" "${PYTHON_PROFILE_PATH}" || return 1; | |
return 0; | |
fi | |
fi | |
wget \ | |
-O "${PYTHON_PROFILE_PATH}" \ | |
--secure-protocol TLSv1 \ | |
'https://gist.githubusercontent.com/shrikeh/7773030d8b237ea3b7c5baab2652d927/raw/python2.7.sh' || return 1; | |
if [ "${CACHE_PYTHON_PROFILE}" = true ]; then | |
# Cache the python 2.7 path locally so we can reuse it - useful for | |
# rebuilding Vagrant or multi-machine to avoid calling out each time. | |
echo "Caching ${PYTHON_PROFILE_PATH} to ${CACHE_PYTHON_PROFILE_PATH}"; | |
mkdir -p "$(dirname ${CACHE_PYTHON_PROFILE_PATH})" 2>&1 >/dev/null ; | |
cp "${PYTHON_PROFILE_PATH}" "${CACHE_PYTHON_PROFILE_PATH}" 2>&1 >/dev/null; | |
fi | |
return 0; | |
} | |
bootstrap_python; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
source /opt/rh/python27/enable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add this to your Provisioning somewhere. | |
$bootstrap_script = 'https://gist.githubusercontent.com/shrikeh/7773030d8b237ea3b7c5baab2652d927/raw/centos6-python-bootstrap.sh' | |
# CentOS 6.8 doesn't come with Python 2.7, so we need to tweak this | |
config.vm.provision 'bootstrap', | |
type: 'shell', | |
path: $bootstrap_script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment