-
Notifications
You must be signed in to change notification settings - Fork 1
/
local_node.sh
executable file
·43 lines (34 loc) · 1.13 KB
/
local_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
#!/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 'Checking script arguments...'
if [ -z "$1" ]; then
echo 'You should provide the password of ansible user as argument for this script'
echo 'Example: sudo ./local_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 software-properties-common python3 python3-pip
echo 'Done'
echo 'Installing ansible...'
pip3 install ansible
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 '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, you can run ansible locally now!'