-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathagentInstaller_debian.sh
200 lines (188 loc) · 4.98 KB
/
agentInstaller_debian.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
# Puppet Agent Install on Debian Wheezy
# Author: John McCarthy
# <http://www.midactstech.blogspot.com> <https://www.github.com/Midacts>
# Date: 26th of February, 2014
# Version 1.1
#
# To God only wise, be glory through Jesus Christ forever. Amen.
# Romans 16:27, I Corinthians 15:1-4
#---------------------------------------------------------------
######## FUNCTIONS ########
function setHostname()
{
# /etc/hosts
IP=`hostname -I`
Hostname=`hostname`
FQDN=`hostname -f`
echo -e "127.0.0.1 localhost localhosts.localdomain $FQDN\n$IP $FQDN $Hostname" > /etc/hosts
echo -e '\e[1;37;42mThe Puppet Agent'\''s "/etc/hosts" file has been updated successfully!\e[0m'
}
function setMasterHostname()
{
# /etc/hosts
echo
echo -e '\e[33mWhat is the IP of your Puppet Master?\e[0m'
read puppetIP
echo -e '\e[33mWhat is your Puppet Master'\''s FQDN?\e[0m'
read puppetFQDN
echo -e '\e[33mWhat is your Puppet Master'\''s hostname?\e[0m'
read puppetHostname
echo -e "$puppetIP $puppetFQDN $puppetHostname puppet" >> /etc/hosts
echo -e '\e[1;37;42mSuccessfully added the Puppet Master to your /etc/hosts file!\e[0m'
}
function puppetRepos()
{
echo
echo -e '\e[01;34m+++ Getting repositories...\e[0m'
wget http://apt.puppetlabs.com/puppetlabs-release-pc1-jessie.deb
dpkg -i puppetlabs-release-pc1-jessie.deb
apt-get update
echo -e '\e[1;37;42mThe Latest Puppet Repos have been acquired!\e[0m'
}
function installPuppet()
{
echo
echo -e '\e[01;34m+++ Installing Puppet Agent...\e[0m'
apt-get install puppet -y
echo -e '\e[1;37;42mThe Puppet Agent has been installed!\e[0m'
}
function editPuppet()
{
if [[ -z "$puppetFQDN" ]]
then
echo -e '\e[33mWhat is your \e[01;33mPuppet Master'\''s\e[0m \e[33mFQDN?\e[0m'
read puppetFQDN
fi
if [[ -z "$FQDN" ]]
then
echo -e '\e[33mWhat is \e[01;33mTHIS Puppet AGENT'\''s\e[0m \e[33mFQDN?\e[0m'
read FQDN
fi
echo
echo -e '\e[01;34m+++ Editing "/etc/puppet/puppet.conf"...\e[0m'
cat <<EOA> /etc/puppet/puppet.conf
[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
factpath=\$vardir/lib/facter
server = $puppetFQDN
report = true
pluginsync = true
certname = $FQDN
[master]
ssl_client_header = SSL_CLIENT_S_DN
ssl_client_verify_header = SSL_CLIENT_VERIFY
[agent]
runinterval = 30m
EOA
echo -e '\e[1;37;42mThe "/etc/puppet/puppet.conf" file has been successfully edited!\e[0m'
}
function enablePuppet()
{
echo
echo -e '\e[01;34m+++ Enabling Puppet Service...\e[0m'
puppet resource service puppet ensure=running enable=true
# Configures puppet to start
sed -i 's/START=no/START=yes/g' /etc/default/puppet
echo -e '\e[1;37;42mThe Puppet Service has been initiated!\e[0m'
}
function editCrontab()
{
echo
echo -e '\e[01;34m+++ Editing the Crontab file...\e[0m'
echo '0,30 * * * * puppet agent --test' >> /var/spool/cron/crontabs/root
echo
echo -e '\e[1;37;42mThe Crontab file has been successfully edited!\e[0m'
}
function doAll()
{
echo
echo -e '\e[33m=== Set Puppet Agent'\''s Hostname for Puppet Runs ? [RECOMMENDED] (y/n)\e[0m'
read yesno
if [ "$yesno" = "y" ]; then
setHostname
fi
echo
echo -e '\e[33m=== Set Puppet Master'\''s Hostname for Puppet Runs ? [RECOMMENDED] (y/n)\e[0m'
read yesno
if [ "$yesno" = "y" ]; then
setMasterHostname
fi
echo
echo -e '\e[33m=== Get Latest Puppet Repos ? (y/n)\e[0m'
read yesno
if [ "$yesno" = "y" ]; then
puppetRepos
fi
echo
echo -e '\e[33m=== Install Puppet Agent ? (y/n)\e[0m'
read yesno
if [ "$yesno" = "y" ]; then
installPuppet
fi
echo
echo -e '\e[33m=== Edit Puppet Configuration File ? (y/n)\e[0m'
read yesno
if [ "$yesno" = "y" ]; then
editPuppet
fi
echo
echo -e '\e[33m=== Enable Puppet Agent Service ? (y/n)\e[0m'
read yesno
if [ "$yesno" = "y" ]; then
enablePuppet
fi
echo
echo -e '\e[33m=== Enable Crontab file to auto-schedule Puppet Runs ? (y/n)\e[0m'
read yesno
if [ "$yesno" = "y" ]; then
editCrontab
fi
clear
echo
echo
echo -e ' \e[01;37;42mWell done! you have completed your Puppet Agent Installation!\e[0m'
echo
echo
echo -e '\e[01;37mCheckout similar material at "midactstech.blogspot.com" and "github.com/Midacts" \e[0m'
echo
echo -e ' \e[01;37m########################\e[0m'
echo -e ' \e[01;37m#\e[0m \e[31mI Corinthians 15:1-4\e[0m \e[01;37m#\e[0m'
echo -e ' \e[01;37m########################\e[0m'
echo
echo
exit 0
}
# Check privileges
[ $(whoami) == "root" ] || die "You need to run this script as root."
# Welcome to the script
clear
echo
echo
echo -e ' \e[01;37;42mWelcome to Midacts Mystery'\''s Puppet Agent Installer!\e[0m'
echo
echo -e ' \e[00;31;40m!!! Do not forget to edit your DNS settings !!!\e[0m'
echo
####### MENU #######
case "$go" in
hostname)
setHostname ;;
masterHostname)
setMasterHostname ;;
repos)
puppetRepos ;;
puppet)
installPuppet ;;
editPuppet)
editPuppet ;;
enablePuppet)
enablePuppet ;;
crontab)
editCrontab ;;
* )
doAll ;;
esac
exit 0