From d6d037da4790e4daf9706714d0a4e716282873d6 Mon Sep 17 00:00:00 2001
From: Adam Henry Lewenberg <adamhl@stanford.edu>
Date: Thu, 8 Dec 2016 09:31:41 -0800
Subject: [PATCH] replace local variables with instance variables in puppet
 conf templates

In s future version of Puppet templates using local variables when they
really should be using instance variable will stop working. So, let's fix
it now.
---
 .../puppetclient/puppet.conf.template.erb     | 56 ++++++++-----------
 templates/puppetclient/puppet.default.erb     |  6 +-
 2 files changed, 27 insertions(+), 35 deletions(-)

diff --git a/templates/puppetclient/puppet.conf.template.erb b/templates/puppetclient/puppet.conf.template.erb
index 63bd8ad..e0cfdc6 100644
--- a/templates/puppetclient/puppet.conf.template.erb
+++ b/templates/puppetclient/puppet.conf.template.erb
@@ -1,6 +1,6 @@
 <%
   # Set a variable that tells us if we are running in a Puppet 3 environment.
-  if (puppetversion =~ /^3\./) then
+  if (@puppetversion =~ /^3\./) then
     puppet3 = true
   else
     puppet3 = false
@@ -11,33 +11,33 @@
   use_directory_environments = puppet3
 
   # For the master section
-  if    (hostname =~ /^jimhenson-dev$/) then
+  if    (@hostname =~ /^jimhenson-dev$/) then
     certname_master = 'jimhenson-dev.stanford.edu'
-  elsif (hostname =~ /^jimhenson\d$/) then
+  elsif (@hostname =~ /^jimhenson\d$/) then
     certname_master = 'jimhenson.stanford.edu'
-  elsif (hostname =~ /^puppetservice1-dev$/) then
+  elsif (@hostname =~ /^puppetservice1-dev$/) then
     certname_master = 'puppetservice1-dev.stanford.edu'
-  elsif (hostname =~ /^puppetservice\d$/) then
+  elsif (@hostname =~ /^puppetservice\d$/) then
     certname_master = 'puppetservice.stanford.edu'
   end
 
   # Figure out what Puppetmaster to use
-  if (server != '') then
-    pserver = server
-  elsif (is_master) then
+  if (@server != '') then
+    pserver = @server
+  elsif (@is_master) then
     pserver = fqdn
   else
-    if (hostname =~ /^(puppetrepo-dev|puppetdb-dev).*$/) then
+    if (@hostname =~ /^(puppetrepo-dev|puppetdb-dev).*$/) then
       pserver = 'puppetservice1-dev.stanford.edu'
     else
       pserver = 'puppetservice.stanford.edu'
     end
-  end 
+  end
 
   # Figure out what Puppet CA service to use.
-  if (ca_server != '') then
-    pca_server = ca_server
-  elsif (hostname =~ /^(puppetservice.*dev|puppetrepo-dev|puppetdb-dev).*$/) then
+  if (@ca_server != '') then
+    pca_server = @ca_server
+  elsif (@hostname =~ /^(puppetservice.*dev|puppetrepo-dev|puppetdb-dev).*$/) then
     pca_server = 'puppetca-dev.stanford.edu'
   else
     pca_server = 'puppetrepo.stanford.edu'
@@ -64,26 +64,22 @@ certname = <%= @certname %>
 
 <% end -%>
 # The Puppet environment to use.
-environment = <%= environment %>
+environment = <%= @environment %>
 
 # Increase the default client timeout to five minutes.
 configtimeout = 300
 
-<% if (runinterval != '') then -%>
+<% if (@runinterval != '') then -%>
 # Change the run interval from the default of 30 minutes.
-runinterval = <%= runinterval %>
+runinterval = <%= @runinterval %>
 
 <% end -%>
 # Make sure all log messages are sent to the right directory
 # This directory must be writable by the puppet user
 logdir = /var/log/puppet
 vardir = /var/lib/puppet
-ssldir = <%= ssldir %>
-rundir = <%= if puppetversion.gsub(/\./, '').to_i >= 240
-             then "/var/run/puppet"
-             else "/var/run"
-           end
-       %>
+ssldir = <%= @ssldir %>
+rundir = /var/run/puppet
 
 # Enable graphing
 graph = true
@@ -93,9 +89,6 @@ report = true
 
 # Enable plugins
 pluginsync = true
-<% if (puppetversion.gsub(/\./, '').to_i < 250) -%>
-pluginsource = puppet://puppet/plugins/
-<% end -%>
 
 # The file in which puppetd stores a list of the classes
 # associated with the retrieved configuratiion.  Can be loaded in
@@ -107,18 +100,17 @@ classfile = $vardir/classes.txt
 # extension indicating the cache format is added automatically.
 # The default value is '$confdir/localconfig'.
 localconfig = $vardir/localconfig
-<% if puppetversion.gsub(/\./, '').to_i >= 240  then -%>
 
-# We want unified diffs (only 0.24.4+ clients)
+# We want unified diffs
 diff_args = '-u'
 show_diff = true
-<% end -%>
 <%
+
    ###################################################################
    ## START
    ## This section will only appear in config files on a puppet master
 -%>
-<% if is_master then -%>
+<% if @is_master then -%>
 
 [master]
 <% if (use_directory_environments) then -%>
@@ -140,7 +132,7 @@ syslogfacility = local2
 logdir = /var/log/puppet
 vardir = /var/lib/puppet
 rundir = /var/run/puppet
-<% if (hostname =~ /jimhenson-dev/) then -%>
+<% if (@hostname =~ /jimhenson-dev/) then -%>
 # If ssldir is not set, the puppet master will read certs from
 # /etc/puppet/ssl which has certs signed from the production puppet
 # service. However, we want the dev puppet master to use its own certs
@@ -170,7 +162,7 @@ manifestdir = /srv/puppet/$environment/manifests
 
 <% end -%>
 # Location of the certificate revocation list
-<% if (hostname =~ /jimhenson-dev/) then -%>
+<% if (@hostname =~ /jimhenson-dev/) then -%>
 cacrl = /srv/puppetmaster/ssl/crl.pem
 <% else -%>
 cacrl = /etc/puppet/ssl/crl.pem
@@ -178,7 +170,7 @@ cacrl = /etc/puppet/ssl/crl.pem
 
 <% if (!puppet3) -%>
 # Location of the ActiveMQ server
-<% if (hostname =~ /jimhenson-dev/) then -%>
+<% if (@hostname =~ /jimhenson-dev/) then -%>
 queue_source = stomp://frankoz1-dev.stanford.edu:61613/
 <% else -%>
 queue_source = stomp://frankoz1.stanford.edu:61613/
diff --git a/templates/puppetclient/puppet.default.erb b/templates/puppetclient/puppet.default.erb
index 64f6afb..efb258d 100644
--- a/templates/puppetclient/puppet.default.erb
+++ b/templates/puppetclient/puppet.default.erb
@@ -2,12 +2,12 @@
 #
 # Default file for the puppet client daemon
 
-<% if pm then -%>
+<% if @pm then -%>
 # Used by the puppetmasters
 KRB5CCNAME=/var/run/puppet/puppet.tgt; export KRB5CCNAME
 <% end -%>
 
-<% if in_noop then -%>
+<% if @in_noop then -%>
 # Used on systems where Puppet shouldn't make changes, only notify the
 # reports list that there are changes pending.
 
@@ -16,4 +16,4 @@ PUPPET_EXTRA_OPTS="--noop"; export PUPPET_EXTRA_OPTS
 # This is the variable needed on Debian.
 DAEMON_OPTS="--noop"
 <% end -%>
-START=<%= start %>
+START=<%= @start %>
-- 
GitLab