I'm no expert by far, but since I have been doing a lot of reading lately for an issue I am trying to resolve, would it make sense to do a define block for this? Looking at
https://docs.puppet.com/puppet/4.9/lang_defined_types.html it seems this
may work for you with some tweaking / testing.
I'm not sure I have all of the syntax right.
something of the order below might work.
define profile::ma ($envfile = "", $envsource = "") {
if $envfile == "" {
$envtarget = '/tmp/filename.sh'
} else {
$envtarget = $envfile
}
if $envsource == "" {
$env_path = "files/filenames.sh"
}
else {
$env_path = $envsource
}
file { $envtarget:
** Note there isn't any handling of "filetocheck" in this snippet, but you can add it.
In your code block for the file you would have something like:
class env_a ($env_file = "/tmp/filename.sh",
$env_source = "files/env_a_file.sh"
){
profile::ma{ 'profilea':
envfile => $env_file,
envsource => $env_source,
}
}
class env_b ($env_file = "/tmp/filename.sh",
$env_source = "files/env_b_file.sh"
){
profile::ma{ 'profilea':
envfile => $env_file,
envsource => $env_source,
}
}
I put in smart parameters for the settings since I use foreman and find I will sometimes need to override a setting value from time to time when something breaks and I need a fix before being able to get the new code through change control.
Now I haven't tested it but it does follow from the linked example above it appears that it should work. There probably also a way to dynamically setup the settings based on the defined environment, but that is beyond me right now.