Skip to content

Commit c1e465a

Browse files
committed
Initial commit
1 parent 25be73d commit c1e465a

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

commit-to-puppet.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
BRANCH=$(git symbolic-ref HEAD 2>/dev/null | awk 'BEGIN { FS="/"; } { print $3; }')
4+
PUPPET='puppetmaster'
5+
git push origin ${BRANCH} \
6+
&& ssh puppetdeploy@${PUPPET} "sudo puppet-deploy"

manifests/site.pp

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node 'puppetmaster' {
2+
include puppet
3+
}

modules/puppet/files/papply.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
SITE='/etc/puppetlabs/code/environments/production'
4+
MODULES='/etc/puppetlabs/code/environments/production/modules'
5+
PUPPET='/opt/puppetlabs/bin/puppet'
6+
7+
sudo ${PUPPET} apply ${SITE} --modulepath=${MODULES} $*

modules/puppet/files/puppet-deploy.sh

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
if [[ $EUID -ne 0 ]]; then
3+
echo "This script must be run as root" 1>&2
4+
exit 1
5+
fi
6+
7+
SRC='/usr/manifests/production'
8+
DEST='/etc/puppetlabs/code/environments/production'
9+
PUPPET='/opt/puppetlabs/bin/puppet'
10+
REPO=''
11+
SUBJECT='Integration to Puppet Master'
12+
RECEIVER='receiver@fqdn'
13+
SERVER_PORT='smtp.server.com:587'
14+
SENDER='sender@fqdn'
15+
USER='mail@fqdn'
16+
PASSWORD=''
17+
18+
[[ ! -d ${DEST} ]] && mkdir ${DEST}
19+
20+
function overwriterepo {
21+
while true; do
22+
echo "Do you want to overwrite puppetmaster repository?"
23+
echo "THIS WILL DESTROY OLD RECIPES! (N/y)"
24+
select yn in "Yes" "No"; do
25+
case $yn in
26+
Yes ) cp -Rpfv ${SRC}/. ${DEST}/. \
27+
&& chown -R puppet:puppet ${DEST} \
28+
&& echo "applying puppet recipes" \
29+
&& ${PUPPET} apply ${DEST}/manifests/site.pp --debug \
30+
&& sendemail
31+
exit 1
32+
;;
33+
No ) exit 1
34+
;;
35+
* ) echo "Please, answer Y or N"
36+
;;
37+
esac
38+
done
39+
done
40+
}
41+
42+
function pullrepo {
43+
(cd ${SRC} && git status)
44+
git pull --git-dir=${SRC}/.git --work-dir=${SRC}
45+
GIT_DIR=${SRC}/.git GIT_WORK_TREE=${SRC} git status
46+
}
47+
48+
function sendemail {
49+
swaks --to $RECEIVER --from $SENDER --server $SERVER_PORT --auth LOGIN --auth-user $USER --auth-password $PASSWORD -tls --data "Date: %DATE%\nTo: %TO_ADDRESS%\nFrom: %FROM_ADDRESS%\nSubject: $SUBJECT %DATE%\nX-Mailer: %NEW_HEADERS%\n ${dif} \n"$
50+
}
51+
52+
function start {
53+
dif=$(colordiff -ENwbur ${DEST} ${SRC})
54+
echo ''
55+
echo 'These will be the changes on puppetmaster:'
56+
if [[ ${dif} != '' ]]; then
57+
echo "${dif}"
58+
echo "Simulate (--noop)?"
59+
select yn in "Yes" "No"; do
60+
case $yn in
61+
Yes ) ${PUPPET} apply --noop ${SRC}/manifests/site.pp \
62+
--modulepath=${SRC}/modules --debug --noop;\
63+
[[ $? == 0 ]] && overwriterepo
64+
;;
65+
No ) overwriterepo
66+
;;
67+
esac
68+
done
69+
else
70+
echo "Nothing changes in repository. Exit"
71+
fi
72+
}
73+
pullrepo && start
74+
exit 0

modules/puppet/manifests/init.pp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class puppet {
2+
file { '/usr/local/bin/papply':
3+
source => 'puppet:///modules/puppet/papply.sh',
4+
mode => '0755',
5+
}
6+
file { '/usr/local/bin/puppet-deploy':
7+
source => 'puppet:///modules/puppet/puppet-deploy.sh',
8+
mode => '0755',
9+
}
10+
}

0 commit comments

Comments
 (0)