-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost-setup.sh
executable file
·49 lines (41 loc) · 1.29 KB
/
host-setup.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
#!/bin/bash
# SPDX-FileCopyrightText: 2022 Wilfred Nicoll <xyzroller@rollyourown.xyz>
# SPDX-License-Identifier: GPL-3.0-or-later
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
helpMessage()
{
echo "host-setup.sh: Use ansible to configure a remote host for project deployment"
echo ""
echo "Help: host-setup.sh"
echo "Usage: ./host-setup.sh -n hostname"
echo "Flags:"
echo -e "-n hostname \t\t(Mandatory) Name of the host to be configured"
echo -e "-h \t\t\tPrint this help message"
echo ""
exit 1
}
errorMessage()
{
echo "Invalid option or mandatory input variable is missing"
echo "Use \"./host-setup.sh -h\" for help"
exit 1
}
while getopts n:h flag
do
case "${flag}" in
n) hostname=${OPTARG};;
h) helpMessage ;;
?) errorMessage ;;
esac
done
if [ -z "$hostname" ]
then
errorMessage
fi
echo "Running host setup playbooks"
echo ""
# Generic host setup
echo "Executing generic host setup playbook for $hostname"
echo "Executing command: ansible-playbook -i "$SCRIPT_DIR"/configuration/inventory_"$hostname" host-setup/setup.yml --extra-vars \"host_id="$hostname"\""
echo ""
ansible-playbook -i "$SCRIPT_DIR"/configuration/inventory_"$hostname" "$SCRIPT_DIR"/host-setup/setup.yml --extra-vars "host_id="$hostname""