On 24/04/18 20:55, Ryan Murphy wrote:
So I've hit a limitation in puppet where I can't modify a variable after its been set.  how do I work around this.  I have a manifest that I need to be able to build up a list of contacts based on certain facts about a server.

Here is an example of my (non functioning) code?  Can anyone give me a suggestion of how to work around this limitation?

|
   if 'sql' in $hostname.downcase or $wl_server_type == 'db' {
     $contactgroups = 'Windows Server Admins,Microsoft SQL DBAs'
   }
   else {
     $contactgroups = 'Windows Server Admins'
   }

   if $wl_app in $btssServers or 'adfs' in $hostname.downcase {
     $contactgroups = "${contactgroups},BT Systems Support"
   }

   if $wl_app == 'hea'{
     $contactgroups = "${contactgroups},HEAT Admins"
   }
|



You could do something like this:

$contactgroups = [
  'Windows Server Admins',

  if 'sql' in $hostname.downcase or $wl_server_type == 'db' {
    'Microsoft SQL DBAs'
  },

  if $wl_app in $btssServers or 'adfs' in $hostname.downcase {
    'BT Systems Support'
  },

  if $wl_app == 'hea' {
    'HEAT Admins'
  }
].filter |$x| { $x =~ NotUndef }.join(',')


It creates an array with the values, each "if" produces a value to include or undef. The "filter" creates a new array where all undef values are dropped, and finally, it calls join to separate them with a comma.

Best,
- henrik



In a language like Python I could just append to the string... but I can't modify the variable at all in Puppet after its been created.



--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/pbo723%24blv%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to