On 2/28/15 1:27 PM, Tom Limoncelli wrote: > I want to copy a hash to a variable but change some settings along the way. > > For example: > > I have $haproxy::params::global_options (which is a hash) and I want > to create a copy with some changes. > > I tried this: > $global_options = $haproxy::params::global_options += { > 'log' => "${log_ip} local0", > } > But that gives me: > Error: Syntax error at '+='; expected '}' at ... > > If I do: > $global_options = $haproxy::params::global_options > $global_options['log'] = "${log_ip} local0" > This gives me: > Error: Assigning to the hash 'global_options' with an existing key > 'log' is forbidden > > Suggestions? > > Tom >
Hi Tom, Suggest using a template as it provides a way to hack around issues involving munging data and types by going straight to ruby. You could use the inline_template() function, though I prefer having it in a separate file for readability and for syntax checking. Here's a quick and dirty hack that might work for you. Notice in the template that the ruby code is between <% %> and the interpolation that is being returned to $hn in your manifest is between <%= %>. manifests/init.pp class tl ( ) { $h = { 'k' => 'v', } $hn = template('tl/hack.erb') notify { 'asdf': message => "h = ${h}", } notify { "hn = ${hn}": require => Notify['asdf'], } } # templates/hack.erb <% ht = {} ht = @h.merge 'log' => "#{@ipaddress} local0"%> <%= ht %> # puppet apply -v tests/init.pp Notice: h = {"k"=>"v"} Notice: hn = {"k"=>"v", "log"=>"10.0.1.3 local0"} Best regards, -g -- Garrett Honeycutt @learnpuppet Puppet Training with LearnPuppet.com Mobile: +1.206.414.8658 -- 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/54F21A1F.2090207%40garretthoneycutt.com. For more options, visit https://groups.google.com/d/optout.