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:
    ensure  => 'present',
    replace => 'no',
    source  => "puppet:///module/${env_path}",
    mode => '0755',
    notify => Exec['install']
  }
  
  exec {'install': 
    command => "${envtarget} -i",
    onlyif => '/usr/bin/test ! -e /etc/filetocheck',
  }
}

** 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. 

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/82430a1d-f044-4a37-964d-096fd61c4490%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to