(GH-1055) Fix hardcoded cache path gh-1055-hardcoded_cache_path
authorCraig Gumbley <craiggumbley@gmail.com>
Mon, 22 Aug 2022 10:23:56 +0000 (10:23 +0000)
committerCraig Gumbley <craiggumbley@gmail.com>
Mon, 22 Aug 2022 19:09:25 +0000 (19:09 +0000)
Prior to this commit the cache path used to create the script file resource
was hardcoded to /opt/puppetlabs/puppet/cache.

This commit fixes that by using the `puppet_vardir` fact provided by stdlib so
that we will always get the correct path for the OS that is executing the code.

Additionally, if for some reason the `puppet_vardir` fact is not available we
will fall back to `tmp`.

manifests/ppa.pp
spec/defines/ppa_spec.rb

index 39852d1b025d1d0af0a89bff45e0fb07b60cfc94..f3613a0b56523fd62b86a49a557271fa8773015a 100644 (file)
@@ -67,8 +67,9 @@ define apt::ppa (
     $trusted_gpg_d_filename = "${dash_filename_no_specialchars}.gpg"
   }
 
-  # This is the location of our main exec script  
-  $script_path = "/opt/puppetlabs/puppet/cache/add-apt-repository-${dash_filename_no_specialchars}-${release}.sh"
+  # This is the location of our main exec script.
+  $cache_path = $facts['puppet_vardir']
+  $script_path = "${cache_path}/add-apt-repository-${dash_filename_no_specialchars}-${release}.sh"
 
   if $ensure == 'present' {
     if $package_manage {
index c056b5ba3df24bf30b8b2ba751df2ea910b2eb1f..74265cde99bbc5376ec31962f70d42cf862e3bb5 100644 (file)
@@ -30,6 +30,7 @@ describe 'apt::ppa' do
             id: 'Ubuntu',
           },
         },
+        puppet_vardir: '/opt/puppetlabs/puppet/cache'
       }
     end
 
@@ -58,6 +59,7 @@ describe 'apt::ppa' do
             id: 'Ubuntu',
           },
         },
+        puppet_vardir: '/opt/puppetlabs/puppet/cache',
       }
     end
 
@@ -96,6 +98,7 @@ describe 'apt::ppa' do
             id: 'Ubuntu',
           },
         },
+        puppet_vardir: '/opt/puppetlabs/puppet/cache',
       }
     end
 
@@ -128,6 +131,7 @@ describe 'apt::ppa' do
             id: 'Ubuntu',
           },
         },
+        puppet_vardir: '/opt/puppetlabs/puppet/cache',
       }
     end
 
@@ -168,6 +172,7 @@ describe 'apt::ppa' do
             id: 'Ubuntu',
           },
         },
+        puppet_vardir: '/opt/puppetlabs/puppet/cache',
       }
     end
 
@@ -210,6 +215,7 @@ describe 'apt::ppa' do
             id: 'Ubuntu',
           },
         },
+        puppet_vardir: '/opt/puppetlabs/puppet/cache',
       }
     end
 
@@ -250,6 +256,7 @@ describe 'apt::ppa' do
             id: 'Ubuntu',
           },
         },
+        puppet_vardir: '/opt/puppetlabs/puppet/cache',
       }
     end
 
@@ -290,6 +297,7 @@ describe 'apt::ppa' do
             id: 'Ubuntu',
           },
         },
+        puppet_vardir: '/opt/puppetlabs/puppet/cache',
       }
     end
 
@@ -328,6 +336,7 @@ describe 'apt::ppa' do
             id: 'Ubuntu',
           },
         },
+        puppet_vardir: '/opt/puppetlabs/puppet/cache',
       }
     end