-
-
Save c0psrul3/d5528a0f11c72d6a49217fdfdf321327 to your computer and use it in GitHub Desktop.
Bootstrap server to use with 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 | |
if [ $# -eq 0 ]; then | |
echo "please supply a servername: bootstrap-server.sh node.example.com" | |
exit 1 | |
fi | |
username=`whoami` | |
# copy public rsa key to server for root user | |
read -r -p "Transfer ssh public keys to server for root? [y/N] " response | |
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then | |
cat ~/.ssh/id_rsa.pub | ssh root@$1 "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys" | |
ssh root@$1 "chmod 0700 ~/.ssh && chmod 0644 ~/.ssh/authorized_keys" | |
fi | |
# install sudo, add user and add user to sudo group | |
read -r -p "This will install sudo, and add $username with sudo rights, continue? [y/N] " response | |
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then | |
ssh root@$1 "apt-get update && apt-get install sudo -y && id $username || (adduser $username && usermod -a -G sudo $username)" | |
fi | |
# copy public rsa key to server for self | |
read -r -p "Transfer ssh public keys to server for "$username"? [y/N] " response | |
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then | |
cat ~/.ssh/id_rsa.pub | ssh $1 "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys" | |
ssh $1 "chmod 0700 ~/.ssh && chmod 0644 ~/.ssh/authorized_keys" | |
fi | |
# install python for ansible | |
read -r -p "Make host ansible ready? [y/N] " response | |
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then | |
ssh root@$1 "apt-get install -y python python-apt python-pycurl" | |
fi | |
# add hostname to ansible_hosts | |
read -r -p "Add to ansible_hosts? [y/N] " response | |
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then | |
echo "[added]\n$1" >> ansible_hosts | |
echo "Added to ansible_hosts, please alter category afterwards!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment