-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreconfigure_foreman
executable file
·90 lines (77 loc) · 2.23 KB
/
reconfigure_foreman
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
function log_and_exit {
echo -e "\n\n\t$1. e.g.\n";
echo -e "\t$2=$3\n"
exit 1;
}
ipaddress=`facter ipaddress_eth1`
if [[ $? -ne 0 ]]; then
log_and_exit "No IP found on interface eth1, check pipework command" "command " " pipework eth0 foreman 10.30.0.2/24"}
fi
enable_dhcp=false
dhcp_range=''
debug=false
ARGS=$(getopt -o s: --long "dhcp-range:,enable-dhcp,help,debug" -n "$0" -- "$@")
[ $? -eq 0 ] || {
echo -e "\tInvalid Options provided"
usage;
exit 1
}
eval set -- "$ARGS";
while true; do
case "$1" in
--dhcp-range)
shift;
if [ -n "$1" ]; then
dhcp_range=$1
shift;
fi
;;
--enable-dhcp)
enable_dhcp=true
shift;
;;
--debug)
debug=true
shift;
;;
--help)
usage
exit 0
shift;
;;
--)
shift;
break;
;;
esac
done
foreman_options="$FOREOPTS \
--enable-foreman-proxy \
--foreman-proxy-tftp=true \
--foreman-proxy-tftp-servername="${ipaddress}" \
--foreman-proxy-dns=true \
--foreman-proxy-dns-interface=eth1 \
--foreman-proxy-dns-zone=`dnsdomainname`\
--foreman-proxy-dns-forwarders=8.8.8.8 \
--foreman-proxy-foreman-base-url=https://`hostname -f`"
if [[ $enable_dhcp == true ]]; then
[[ -z $dhcp_range ]] && { log_and_exit "No dhcp range provided" "--dhcp-range" "10.30.0.100 10.30.0.200"; }
foreman_options="$foreman_options \
--foreman-proxy-dhcp=true \
--foreman-proxy-dhcp-interface=eth1 \
--foreman-proxy-dhcp-gateway=\"${ipaddress}\" \
--foreman-proxy-dhcp-nameservers=\"${ipaddress}\" \
--foreman-proxy-dhcp-range=\"${dhcp_range}\""
fi
eval foreman-installer $foreman_options
# Wait again for processes to start
sleep 60;
echo "Setting up Provisioning Template..."
hammer -s localhost -u admin -p changeme template update --name "PXELinux global default" --file /tmp/pxe_global_default
echo "Building Default PXE Profile..."
curl -s -H "Accept:application/json" -k -u admin:changeme https://localhost/api/config_templates/build_pxe_default
# Tail the log, to prevent the process from exiting, and return
# feedback to the console about the execution of the above.
#
tail -f /var/log/foreman-installer/foreman-installer.log