-
Notifications
You must be signed in to change notification settings - Fork 1
/
target_node.sh
executable file
·55 lines (45 loc) · 1.38 KB
/
target_node.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
#!/bin/bash
echo 'setting -e flag set, so the script will stop if any command inside it fails...'
set -e
echo 'Done'
echo 'Checking if the script was executed with sudo...'
if [ "$EUID" != 0 ]; then
echo 'This script must be run as root'
exit 1
fi
echo 'Done'
echo 'Checking script arguments...'
if [ -z "$1" ]; then
echo 'You should provide the password of ansible user as argument for this script'
echo 'Ansible user will be used to provision your Ubuntu OS'
echo 'Example: ./target_node mySuperStrongPassword'
exit 1
else
password="$1"
echo 'Password received'
fi
echo 'Done'
echo 'Installing required dependencies...'
apt update 2>/dev/null && apt install -y openssh-server
echo 'Done'
echo 'Launching ssh service...'
systemctl status ssh --no-pager
systemctl enable ssh
if [ $? -eq 0 ]; then
echo "ssh server is running"
else
systemctl stargnot ssh
fi
echo 'Done'
echo 'Creating user ansible to provision...'
userdel -rf ansible || true
useradd -m ansible
echo -e "$password\n$password" | passwd ansible
echo 'Done'
echo 'Opening firewall to allow ssh connections...'
ufw allow ssh
echo 'Done'
echo 'Append ansible user to sudoers not to have to provide the password while provisioning remotely...'
(echo ; echo 'ansible ALL=(ALL) NOPASSWD: ALL') >> /etc/sudoers
echo 'Done'
echo 'Preparation is done, this node is configured as target for ansible!'