Skip to content

Instantly share code, notes, and snippets.

@ewized
Last active August 30, 2016 22:59
Show Gist options
  • Save ewized/ff1709886bac7561210acff396ef26bb to your computer and use it in GitHub Desktop.
Save ewized/ff1709886bac7561210acff396ef26bb to your computer and use it in GitHub Desktop.
Ansible bootstrap script that sets up the requirements to run a remote playbook
# This python script is a lightweight script that ensures that the proper
# packages are installed on the remote host, must have hostname defined
# $ hostname new-host ; wget -O - goo.gl/G3JWa4 | python
import os
import sys
print('-' * 5 + ' [Ansible Bootstrap Script] ' + '-' * 5)
# Allow to run in python2 or python3
if sys.version[0] > '2':
print('Making sure python 2 is installed')
# Run bash commands to install python-minimal if its not installed
os.system('! dpkg -s python-minimal && apt install -y python-minimal')
# Run bash commands to set up the hostname
os.system('hostname > /etc/hostname')
os.system('tail -n+3 /etc/hosts > /tmp/hosts')
os.system('echo 127.0.0.1 localhost > /etc/hosts')
os.system('echo "127.0.1.1 $(hostname)" >> /etc/hosts')
os.system('cat /tmp/hosts >> /etc/hosts')
print('Making sure ssh is installed')
# Run bash commands to install ssh if its not installed
os.system('! dpkg -s ssh && apt install -y ssh')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment