On Tuesday, March 4, 2014 3:56:48 PM UTC-6, Virtual_user wrote:
>
>
> Hi
> i am using puppet 2.7
>
> i want to echo the Fqdn name in a template by using looping through the
> hash,
>
> Example, in site.pp i have
>
> $acc_sudo = $mc_servertype ? {
> 'system' => [ '%APP *<%= fqdn %>* =/etc/init.d/httpd start,
> /etc/init.d/httpd stop,/etc/init.d/httpd restart, /sbin/services httpd
> restart' ],
> 'db' => [ '%DB <%= fqdn %> =/etc/init.d/oracle start'],
> 'app' => ['%APP <%= fqdn %> =/etc/init.d/httpd start,
> /etc/init.d/httpd stop,/etc/init.d/httpd restart, /sbin/services httpd
> restart' ],
>
> }
>
>
There is no hash there. You are using a Puppet language feature called a
"selector" to assign a value to variable $acc_sudo based on the value of
variable $mc_servertype. (Which value, by the way, is in each case an
array containing exactly one string. Weird.)
>
>
> and sudo.erb file i have
>
> <% if mc_servertype == "system" %>
>
> <% acc_sudo.each do |sudo| %><%= sudo %><% end %>
>
> <% end %>
>
> problem is, when its generating the sudo file, its writing like this
>
> %APP *<%= fqdn %>*=/etc/init.d/httpd start, /etc/init.d/httpd
> stop,/etc/init.d/httpd restart, /sbin/services httpd restart
>
>
Of course it does. Each element of variable acc_sudo is a string. Your
template says to insert that string into the result, not to interpret it as
another template.
>
> but i want to make it like this
>
> %APP server1.test.co=/etc/init.d/httpd start, /etc/init.d/httpd
> stop,/etc/init.d/httpd restart, /sbin/services httpd restart
>
>
> what will be the right syntax for it in site.pp ??
>
>
You are making it harder than it needs to be. What you are after can be
accomplished with ordinary variable interpolation:
$acc_sudo = $mc_servertype ? {
'system' => [ "%APP ${fqdn} =/etc/init.d/httpd start,
/etc/init.d/httpd stop,/etc/init.d/httpd restart, /sbin/services httpd
restart" ],
'db' => [ "%DB ${fqdn} =/etc/init.d/oracle start" ],
'app' => [ "%APP ${fqdn} =/etc/init.d/httpd start,
/etc/init.d/httpd stop,/etc/init.d/httpd restart, /sbin/services httpd
restart" ],
}
Note there that (1) the variable interpolation is performed when the string
is initialized, as opposed to when the template is processed, and (2)
variables are interpolated into double-quoted strings only, not into
single-quoted strings.
John
--
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/7cb1adc5-6e02-43ca-850e-c460fcf1ac11%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.