Syntax for echoing Fqdn name inside a hash value (please help)

42 views
Skip to first unread message

Virtual_user

unread,
Mar 4, 2014, 4:56:48 PM3/4/14
to puppet...@googlegroups.com

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' ],

}



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


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 ??

please help with this.




jcbollinger

unread,
Mar 5, 2014, 10:02:49 AM3/5/14
to puppet...@googlegroups.com


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

Reply all
Reply to author
Forward
0 new messages