Skip to content

Commit 522d472

Browse files
committed
Updated scripts
1 parent 2397e9e commit 522d472

9 files changed

+100
-65
lines changed

Puppetfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# External modules to installed by r10k in modules/ dir
22
# Here mostly at latest version for sample purposes.
3-
# In working environments specific versions should be defined.
3+
# In working environments specific fixed versions should be defined.
44

55
# Here we place hieradata in a separated module.
66
# We use control-repo branch if exists, or production as default
@@ -81,5 +81,8 @@ mod 'puppet/staging', :latest
8181
# mod 'counsyl/windows', :git => 'https://github.com/counsyl/puppet-windows'
8282
# mod 'trlinkin/domain_membership', :git => 'https://github.com/trlinkin/domain_membership'
8383

84+
# Used by Mac profiles
85+
# mod 'thekevjames-homebrew', :latest
86+
8487
# Used by psick::users when module=puppetlabs
8588
# mod 'puppetlabs/accounts', :latest

bin/bootstrap/tp_cli.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
PATH=/opt/puppetlabs/puppet/bin:$PATH
3+
4+
if [ $USER == 'root' ]; then
5+
sudo_command=''
6+
else
7+
sudo_command='sudo '
8+
fi
9+
10+
$sudo_command puppet module install example42-tp
11+
12+
os=$(facter operatingsystem)
13+
local_user=$(whoami)
14+
case $os in
15+
Darwin*)
16+
$sudo_command puppet module install thekevjames-homebrew
17+
$sudo_command puppet apply -e "class { homebrew: user => $local_user }"
18+
;;
19+
Windows*)
20+
$sudo_command puppet module install puppetlabs-chocolatey
21+
$sudo_command puppet apply -e "include chocolately"
22+
;;
23+
esac
24+
25+
$sudo_command puppet tp setup
26+

bin/docker_setup.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ repo_dir=$(git rev-parse --show-toplevel)
55
puppet_options="--modulepath ${repo_dir}/site:${repo_dir}/modules:/etc/puppet/modules --environmentpath ${repo_dir} --hiera_config ${repo_dir}/hiera.yaml"
66

77
echo_title "Going to install Docker"
8-
echo_subtitle "You will probably need superuser powers"
9-
puppet apply $puppet_options -e 'include docker'
8+
echo_subtitle "You need sudo powers. Executing: sudo -E puppet apply -e 'include psick::docker'"
9+
sudo -E puppet apply $puppet_options -e 'include psick ; include psick::docker'
1010

bin/fabric_setup.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ puppet_options="--modulepath ${repo_dir}/site:${repo_dir}/modules:/etc/puppet/mo
66

77
echo_title "Going to install Fabric"
88
echo_subtitle "Once installed run fab -l"
9-
puppet apply $puppet_options -e 'include psick::python::fabric'
9+
echo_subtitle "You need sudo powers. Executing: sudo -E puppet apply -e 'include psick::python::fabric'"
10+
11+
sudo -E puppet apply $puppet_options -e 'include psick ; include psick::python::fabric'
1012

bin/functions

+5
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,8 @@ shell_filter_strict () {
8484
# echo $1 | sed "s/[^a-Z0-9_\-]//Ig"
8585
}
8686

87+
if [ $USER == 'root' ]; then
88+
sudo_command=''
89+
else
90+
sudo_command='sudo '
91+
fi

bin/puppet_install.sh

+38-33
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env bash
22
breed=$1
3-
3+
if [ $USER == 'root' ]; then
4+
sudo_command=''
5+
else
6+
sudo_command='sudo '
7+
fi
48
which tput >/dev/null 2>&1
59
if [ "x${?}" == "x0" ]; then
610
SETCOLOR_NORMAL=$(tput sgr0)
@@ -27,14 +31,14 @@ fi
2731

2832
setup_redhat() {
2933
echo_title "Uninstalling existing Puppet"
30-
yum erase -y puppet-agent puppet puppetlabs-release puppetlabs-release-pc1 >/dev/null 2>&1
34+
$sudo_command yum erase -y puppet-agent puppet puppetlabs-release puppetlabs-release-pc1 >/dev/null 2>&1
3135

3236
echo_title "Adding repo for Puppet 5"
33-
rpm -ivh https://yum.puppetlabs.com/puppet5/puppet5-release-el-$1.noarch.rpm >/dev/null 2>&1
37+
$sudo_command rpm -ivh https://yum.puppetlabs.com/puppet5/puppet5-release-el-$1.noarch.rpm >/dev/null 2>&1
3438

3539
sleep 2
3640
echo_title "Installing Puppet"
37-
yum install -y puppet-agent >/dev/null 2>&1
41+
$sudo_command yum install -y puppet-agent >/dev/null 2>&1
3842
}
3943

4044
setup_fedora() {
@@ -44,44 +48,44 @@ setup_fedora() {
4448
release='26'
4549
fi
4650
echo_title "Uninstalling existing Puppet"
47-
yum erase -y puppet-agent puppet puppetlabs-release puppetlabs-release-pc1 >/dev/null 2>&1
51+
$sudo_command yum erase -y puppet-agent puppet puppetlabs-release puppetlabs-release-pc1 >/dev/null 2>&1
4852

4953
echo_title "Adding repo for Puppet 5"
50-
rpm -ivh https://yum.puppetlabs.com/puppet5/puppet5-release-fedora-${release}.noarch.rpm
54+
$sudo_command rpm -ivh https://yum.puppetlabs.com/puppet5/puppet5-release-fedora-${release}.noarch.rpm
5155

5256
sleep 2
5357
echo_title "Installing Puppet"
54-
yum install -y puppet-agent
58+
$sudo_command yum install -y puppet-agent
5559
}
5660

5761
setup_amazon() {
5862
echo_title "Uninstalling existing Puppet"
59-
yum erase -y puppet-agent puppet puppetlabs-release puppetlabs-release-pc1 >/dev/null 2>&1
63+
$sudo_command yum erase -y puppet-agent puppet puppetlabs-release puppetlabs-release-pc1 >/dev/null 2>&1
6064

6165
echo_title "Adding repo for Puppet 4"
62-
rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-pc1-el-6.noarch.rpm >/dev/null 2>&1
63-
yum-config-manager --enable epel
64-
yum-config-manager --setopt="puppetlabs-pc1.priority=1" --save
66+
$sudo_command rpm -ivh https://yum.puppetlabs.com/puppetlabs-release-pc1-el-6.noarch.rpm >/dev/null 2>&1
67+
$sudo_command yum-config-manager --enable epel
68+
$sudo_command yum-config-manager --setopt="puppetlabs-pc1.priority=1" --save
6569

6670
sleep 2
6771
echo_title "Installing Puppet"
68-
yum install -y puppet-agent >/dev/null 2>&1
72+
$sudo_command yum install -y puppet-agent >/dev/null 2>&1
6973
}
7074

7175
setup_suse() {
7276
echo_title "Uninstalling existing Puppet"
73-
zypper remove -y puppet >/dev/null 2>&1
74-
zypper remove -y puppet-agent >/dev/null 2>&1
75-
zypper remove -y puppetlabs-release >/dev/null 2>&1
76-
zypper remove -y puppetlabs-release-pc1 >/dev/null 2>&1
77+
$sudo_command zypper remove -y puppet >/dev/null 2>&1
78+
$sudo_command zypper remove -y puppet-agent >/dev/null 2>&1
79+
$sudo_command zypper remove -y puppetlabs-release >/dev/null 2>&1
80+
$sudo_command zypper remove -y puppetlabs-release-pc1 >/dev/null 2>&1
7781

7882
echo_title "Adding repo for Puppet 5"
79-
wget https://yum.puppetlabs.com/puppet5/puppet5-release-sles-$1.noarch.rpm 2>&1
80-
rpm -ivh puppet5-release-sles-$1.noarch.rpm 2>&1
83+
$sudo_command wget https://yum.puppetlabs.com/puppet5/puppet5-release-sles-$1.noarch.rpm 2>&1
84+
$sudo_command rpm -ivh puppet5-release-sles-$1.noarch.rpm 2>&1
8185

8286
sleep 2
8387
echo_title "Installing Puppet"
84-
zypper --no-gpg-checks --non-interactive install puppet-agent
88+
$sudo_command zypper --no-gpg-checks --non-interactive install puppet-agent
8589
}
8690

8791
setup_apt() {
@@ -94,43 +98,42 @@ setup_apt() {
9498
12.04) codename=precise ;;
9599
14.04) codename=trusty ;;
96100
16.04) codename=xenial ;;
97-
18.04) codename=stretch ;; # Temporary fix, waiting for official repos
98101
*) echo "Release not supported" ;;
99102
esac
100103

101104
echo_title "Adding repo for Puppet 5"
102-
wget -q "http://apt.puppetlabs.com/puppet5-release-${codename}.deb" >/dev/null
103-
dpkg -i "puppet5-release-${codename}.deb" >/dev/null
105+
$sudo_command wget -q "http://apt.puppetlabs.com/puppet5-release-${codename}.deb" >/dev/null
106+
$sudo_command dpkg -i "puppet5-release-${codename}.deb" >/dev/null
104107

105108
echo_title "Running apt-get update"
106-
apt-get update >/dev/null 2>&1
109+
$sudo_command apt-get update >/dev/null 2>&1
107110

108111
echo_title "Installing Puppet and its dependencies"
109-
apt-get install -y puppet-agent -y >/dev/null
110-
apt-get install -y apt-transport-https -y >/dev/null
112+
$sudo_command apt-get install -y puppet-agent -y >/dev/null
113+
$sudo_command apt-get install -y apt-transport-https -y >/dev/null
111114
}
112115
setup_alpine() {
113116
echo "## Adding repo for Ruby to /etc/apk/repositories"
114117
echo http://dl-4.alpinelinux.org/alpine/edge/testing/ >> /etc/apk/repositories
115118
echo "## Running apk update"
116-
apk update
119+
$sudo_command apk update
117120

118121
echo "## Installing Puppet and its dependencies"
119-
apk add shadow ruby less bash
120-
gem install puppet --no-rdoc -no-ri
122+
$sudo_command apk add shadow ruby less bash
123+
$sudo_command gem install puppet --no-rdoc -no-ri
121124
}
122125
setup_solaris() {
123126
echo_title "Not yet supported"
124127
}
125128
setup_darwin() {
126129
majver=$(sw_vers -productVersion | cut -d '.' -f 1-2)
127-
echo_title "Downloading package for version ${majver}"
128-
curl -s -o puppet-agent.dmg "https://downloads.puppetlabs.com/mac/puppet5/${majver}/x86_64/puppet-agent-5.3.2-1.osx${majver}.dmg"
130+
echo_title "Downloading package for MacOS version ${majver}"
131+
curl -s -o puppet-agent.dmg "https://downloads.puppetlabs.com/mac/puppet5/${majver}/x86_64/puppet-agent-latest.dmg"
129132

130133
echo_title "Installing Puppet Agent"
131134
hdiutil mount puppet-agent.dmg
132135
package=$(find /Volumes/puppet-agent* | grep pkg)
133-
installer -pkg $package -target /
136+
$sudo_command installer -pkg $package -target /
134137
hdiutil unmount /Volumes/puppet-agent*
135138
}
136139
setup_bsd() {
@@ -205,11 +208,13 @@ os_detect() {
205208
esac
206209
}
207210

211+
echo "Going to install Puppet (and eventually cleanup old version)"
212+
echo "If you are not root some commands will be run via sudo"
208213
if [ "x$breed" != "x" ]; then
209214
setup_$breed
210215
else
211216
os_detect
212217
fi
213-
[ -e /usr/bin/puppet ] || ln -fs /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet
214-
[ -e /usr/bin/facter ] || ln -fs /opt/puppetlabs/puppet/bin/facter /usr/bin/facter
218+
[ -e /usr/bin/puppet ] || $sudo_command ln -fs /opt/puppetlabs/puppet/bin/puppet /usr/bin/puppet
219+
[ -e /usr/bin/facter ] || $sudo_command ln -fs /opt/puppetlabs/puppet/bin/facter /usr/bin/facter
215220

bin/puppet_setup.sh

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ script_dir="$(dirname $0)"
44
# repo_dir=$(git rev-parse --show-toplevel)
55
. "${script_dir}/functions"
66

7-
PATH=$PATH:/usr/local/bin
7+
PATH=/opt/puppetlabs/puppet/bin:$PATH
88
if [ "$1" = "auto" ]; then
99
auto=true
1010
fi
@@ -16,32 +16,32 @@ install_gems() {
1616
[ "$?" = 0 ] || return
1717

1818
echo_title "Installing gems"
19-
puppet resource package rubygems ensure=present
19+
$sudo_command puppet resource package rubygems ensure=present
2020
which gem || echo "You need gem support! Install rubygems to continue successfully"
2121
echo
22-
echo_subtitle "Installing with /bin/gem"
23-
gem install deep_merge --no-ri --no-rdoc
24-
gem install hiera-eyaml --no-ri --no-rdoc
25-
gem install r10k --no-ri --no-rdoc
22+
echo_subtitle "Installing with gem"
23+
$sudo_command gem install deep_merge --no-ri --no-rdoc
24+
$sudo_command gem install hiera-eyaml --no-ri --no-rdoc
25+
$sudo_command gem install r10k --no-ri --no-rdoc
2626
if [ -x /opt/puppetlabs/puppet/bin/gem ]; then
2727
echo_subtitle "Installing with /opt/puppetlabs/puppet/bin/gem"
28-
/opt/puppetlabs/puppet/bin/gem install deep_merge --no-ri --no-rdoc
29-
/opt/puppetlabs/puppet/bin/gem install hiera-eyaml --no-ri --no-rdoc
30-
/opt/puppetlabs/puppet/bin/gem install r10k --no-ri --no-rdoc
28+
$sudo_command /opt/puppetlabs/puppet/bin/gem install deep_merge --no-ri --no-rdoc
29+
$sudo_command /opt/puppetlabs/puppet/bin/gem install hiera-eyaml --no-ri --no-rdoc
30+
$sudo_command /opt/puppetlabs/puppet/bin/gem install r10k --no-ri --no-rdoc
3131
fi
3232
if [ -x /opt/puppetlabs/bin/puppetserver ]; then
3333
echo_subtitle "Installing with /opt/puppetlabs/bin/puppetserver"
34-
/opt/puppetlabs/bin/puppetserver gem install deep_merge
35-
/opt/puppetlabs/bin/puppetserver gem install hiera-eyaml
36-
/opt/puppetlabs/bin/puppetserver gem install r10k
34+
$sudo_command /opt/puppetlabs/bin/puppetserver gem install deep_merge
35+
$sudo_command /opt/puppetlabs/bin/puppetserver gem install hiera-eyaml
36+
$sudo_command /opt/puppetlabs/bin/puppetserver gem install r10k
3737
fi
3838
}
3939

4040
install_rsync() {
4141
echo_title "Installing rsync"
42-
[ "$auto" = "true" ] || ask_interactive "Can we install rsync? Note: You need sudo powers"
42+
[ "$auto" = "true" ] || ask_interactive "Can we install rsync?"
4343
[ "$?" = 0 ] || return
44-
sudo -E puppet resource package rsync ensure=present
44+
$sudo_command puppet resource package rsync ensure=present
4545
}
4646

4747
install_modules() {

bin/setup.sh

+6-13
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,37 @@
22
repo_dir="$(dirname $0)/.."
33
script_dir="$(dirname $0)"
44
. "${script_dir}/functions"
5+
PATH=/opt/puppetlabs/puppet/bin:$PATH
56

67
[ "$1" = "auto" ] && auto=true || auto=false
78

89
puppet_options="--modulepath ${repo_dir}/site:${repo_dir}/modules:/etc/puppet/modules --environmentpath ${repo_dir}"
910

1011
setup_puppet() {
1112
echo_title "Setting up Puppet environment"
12-
if [ "$auto" = "true" ]; then
13+
if [ "$auto" == "true" ]; then
1314
"${script_dir}/puppet_setup.sh" auto
1415
else
1516
"${script_dir}/puppet_setup.sh"
1617
fi
1718
}
1819

1920
install_fabric() {
20-
[ "$auto" = "true" ] || ask_interactive "Going to install Fabric via Puppet"
21+
[ "$auto" == "true" ] || ask_interactive "Going to install Fabric via Puppet"
2122
[ "$?" = 0 ] || return
22-
echo_title "Installing Fabric"
23-
echo_subtitle "Executing: sudo puppet apply -e 'include ::psick::python::fabric'"
24-
sudo -E puppet apply $puppet_options -e 'include psick ; include ::psick::python::fabric'
23+
"${script_dir}/fabric_setup.sh"
2524
}
2625

2726
install_vagrant() {
2827
[ "$auto" = "true" ] || ask_interactive "Going to install Vagrant via Puppet"
2928
[ "$?" = 0 ] || return
30-
echo_title "Installing Vagrant"
31-
echo_subtitle "Executing: sudo puppet apply -e 'include psick ; include ::psick::vagrant'"
32-
sudo -E puppet apply $puppet_options -e 'include psick ; include ::psick::vagrant'
33-
echo_subtitle "Executing: puppet apply -e 'include psick ; include ::psick::vagrant::plugins'"
34-
sudo -E puppet apply $puppet_options -e 'include psick ; include ::psick::vagrant::plugins'
29+
"${script_dir}/vagrant_setup.sh"
3530
}
3631

3732
install_docker() {
3833
[ "$auto" = "true" ] || ask_interactive "Going to install Docker via Puppet"
3934
[ "$?" = 0 ] || return
40-
echo_title "Installing Docker"
41-
echo_subtitle "Executing: sudo puppet apply -e 'include psick ; include ::psick::docker'"
42-
sudo -E puppet apply $puppet_options -e 'include psick ; include ::psick::docker'
35+
"${script_dir}/docker_setup.sh"
4336
}
4437

4538
setup_puppet

bin/vagrant_setup.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ repo_dir=$(git rev-parse --show-toplevel)
55
puppet_options="--modulepath ${repo_dir}/site:${repo_dir}/modules:/etc/puppet/modules --environmentpath ${repo_dir}"
66

77
echo_title "Going to install vagrant and the needed plugins"
8-
puppet apply $puppet_options -e 'include psick::vagrant::plugins'
8+
echo_subtitle "Executing: sudo -E puppet apply -e 'include psick::vagrant'"
9+
sudo -E puppet apply $puppet_options -e 'include psick::vagrant'
910

0 commit comments

Comments
 (0)