From 4f3c649d1d1564d97989e0ec4f5c736ac2d60157 Mon Sep 17 00:00:00 2001
From: "A. Karl Kornel" <akkornel@stanford.edu>
Date: Thu, 17 Nov 2016 10:04:57 -0800
Subject: [PATCH] wallet: Test for running in a builder environment

---
 manifests/wallet.pp | 52 ++++++++++++++++++++++++++++-----------------
 1 file changed, 32 insertions(+), 20 deletions(-)

diff --git a/manifests/wallet.pp b/manifests/wallet.pp
index a2a2a60..70cb970 100644
--- a/manifests/wallet.pp
+++ b/manifests/wallet.pp
@@ -31,6 +31,15 @@
 #         path => '/etc/foobar/password',
 #         type => 'file',
 #     }
+#
+# It is important to note that, by default, this code will use the host's
+# keytab (located at /etc/krb5.keytab), so you will need to have that in
+# place before your Puppet code runs.  Or, you can pass a keytab file path
+# using the $auth_keytab variable.
+#
+# Also, if base::wallet detects that it is being run under Packer, then
+# it will not do anything.  If you want it to run under Packer, then set
+# $build_ok to true, and also set $auth_keytab appropriately.
 
 # These helper routines are broken out separately to reduce indentation, but
 # shouldn't be called separately.  They're purely an implementation detail.
@@ -46,6 +55,7 @@ define base::wallet(
   $type           = 'keytab',
   $onlyif         = 'NONE',
   $heimdal        = false,
+  $build_ok       = false,
   $path
 ) {
   case $auth_principal {
@@ -62,27 +72,29 @@ define base::wallet(
         file { $path: ensure => absent }
     }
     'present': {
-      case $type {
-        'keytab': {
-          base::wallet::keytab { $name:
-            kstart_cmd => $kstart_cmd,
-            path       => $path,
-            primary    => $primary,
-            mode       => $mode,
-            owner      => $owner,
-            group      => $group,
-            heimdal    => $heimdal,
+      if ($build_ok or !$::packer_build_name) {
+        case $type {
+          'keytab': {
+            base::wallet::keytab { $name:
+              kstart_cmd => $kstart_cmd,
+              path       => $path,
+              primary    => $primary,
+              mode       => $mode,
+              owner      => $owner,
+              group      => $group,
+              heimdal    => $heimdal,
+            }
           }
-        }
-        default: {
-          base::wallet::other { $name:
-            kstart_cmd => $kstart_cmd,
-            path       => $path,
-            type       => $type,
-            mode       => $mode,
-            owner      => $owner,
-            group      => $group,
-            onlyif     => $onlyif,
+          default: {
+            base::wallet::other { $name:
+              kstart_cmd => $kstart_cmd,
+              path       => $path,
+              type       => $type,
+              mode       => $mode,
+              owner      => $owner,
+              group      => $group,
+              onlyif     => $onlyif,
+            }
           }
         }
       }
-- 
GitLab