-
Notifications
You must be signed in to change notification settings - Fork 0
/
sshautomation.sh
59 lines (50 loc) · 1.56 KB
/
sshautomation.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
clear
GREEN='\033[0;32m'
NC='\033[0m'
sshserveradress=""
# Install openssh-client on Ansible Controller
sudo apt update
sudo apt install openssh-client
sudo apt install software-properties-common
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt install ansible
# Printer for messages
printer() {
printf "\n$GREEN****************************************************************************\n"
printf "\n$1\n"
printf "\n****************************************************************************$NC\n\n"
}
# Function to read Server information
function readserverinfos() {
read -r -p "What is your Servers IP: " ipadress
read -r -p "What is your username on the Server: " username
sshserveradress=$username"@"$ipadress
}
function installansibleonnode() {
ssh sshserveradress 'sudo su && apt install ansible ansible-core ansible-galaxy -y'
echo $(apt list --installed | grep ansible) is Installed
echo $(apt list --installed | grep ansible-core) is Installed
echo $(apt list --installed | grep ansible-galaxy) is Installed
}
# Function for SSH keys creation
function sshkeyscreation() {
ssh-keygen -t rsa -b 4096 -f ~/.ssh/homeserver
}
# Function for SSH keys Copying
function copysshkeys(){
ssh-copy-id -i ~/.ssh/homeserver "$sshserveradress"
}
# Script Entry Point
printer "This Script will Automate Ansible Installation and SSH Key management"
readserverinfos
clear
printer "SSH Key Management"
sshkeyscreation
copysshkeys
sleep 5
clear
printer "Installing Ansible on Node"
sleep 5
installansibleonnode
clear