Project

General

Profile

Download (1.96 KB) Statistics
| Branch: | Tag: | Revision:
<%#
kind: snippet
name: puppet_setup
description: this snippet will configure the Puppet agent
%>
<%
if @host.operatingsystem.family == 'Freebsd'
freebsd_package = @host.param_true?('enable-puppet4') ? 'puppet4' : 'puppet38'
etc_path = '/usr/local/etc/puppet'
bin_path = '/usr/local/bin'
elsif @host.param_true?('enable-puppetlabs-pc1-repo')
linux_package = 'puppet-agent'
etc_path = '/etc/puppetlabs/puppet'
bin_path = '/opt/puppetlabs/bin'
else
linux_package = 'puppet'
etc_path = '/etc/puppet'
bin_path = '/usr/bin'
end
%>

<% if @host.operatingsystem.family == 'Debian' -%>
apt-get update
apt-get install -y <%= linux_package %>
<% elsif @host.operatingsystem.family == 'Freebsd' -%>
pkg install -y <%= freebsd_package %>
<% elsif @host.operatingsystem.family == 'Redhat' -%>
yum -t -y install <%= linux_package %>
<% end -%>

cat > <%= etc_path %>/puppet.conf << EOF
<%= snippet 'puppet.conf' %>
EOF

<% unless @host.param_true?('enable-puppetlabs-pc1-repo') -%>
<% if @host.operatingsystem.family == 'Debian' -%>
if [ -f "/etc/default/puppet" ]
then
/bin/sed -i 's/^START=no/START=yes/' /etc/default/puppet
fi
/usr/bin/puppet agent --enable
<% elsif @host.operatingsystem.family == 'Freebsd' -%>
echo 'puppet_enable="YES"' >>/etc/rc.conf
<% elsif @host.operatingsystem.name == 'Fedora' -%>
puppet_unit=puppet
/usr/bin/systemctl list-unit-files | grep -q puppetagent && puppet_unit=puppetagent
/usr/bin/systemctl enable ${puppet_unit}
<% elsif @host.operatingsystem.family == 'Redhat' -%>
/sbin/chkconfig --level 345 puppet on
<% elsif @host.operatingsystem.family == 'Suse' -%>
if [ -f "/etc/sysconfig/puppet" ]
then
/usr/bin/sed -ie s/^PUPPET_SERVER=.*/PUPPET_SERVER=<%= @host.puppetmaster.blank? ? '' : @host.puppetmaster %>/ /etc/sysconfig/puppet
fi
/sbin/chkconfig puppet on -f
<% end -%>
<% end -%>

<%= bin_path %>/puppet agent --config <%= etc_path %>/puppet.conf --onetime --tags no_such_tag <%= @host.puppetmaster.blank? ? '' : "--server #{@host.puppetmaster}" %> --no-daemonize
(11-11/16)