inline_template not working after migrated to puppet5

155 views
Skip to first unread message

Suresh P

unread,
Jul 9, 2018, 12:12:02 PM7/9/18
to Puppet Users
Hi,

I used following code in puppet3.8.x,  it worked well. 

After i migrated to Puppet5 it throws error.

$header="LD_LIBRARY_PATH=$destdir:\$LD_LIBRARY_PATH\n\nexport LD_LIBRARY_PATH\n"
$content = inline_template('<%= header+"\n"+ports.map {|port| memcache_command+" -m "+memory_per_instance+" -p "+port+" &"}.join("\n")+"\n" %>')
file { "$destdir/startmemcached.sh":
    ensure => file,
    owner => $title,
    group => $title,
    mode => '0744',
    content => inline_template($content),
}

Error:
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, Failed to parse inline template: undefined local variable or method `header' for #<Puppet::Parser::TemplateWrapper:0x5f6a0cd8> (file: /home/sas/in2_puppet/environments/production/modules/pkg/manifests/memcache/installmemcache.pp, line: 45, column: 12) (file: /home/sas/in2_puppet/environments/production/modules/in2/manifests/memcache/common.pp, line: 13) on node


Can you help me on this.

Regards,
Suresh

Henrik Lindberg

unread,
Jul 9, 2018, 1:06:51 PM7/9/18
to puppet...@googlegroups.com
On 2018-07-09 18:12, Suresh P wrote:
> Hi,
>
> I used following code in puppet3.8.x,  it worked well.
>
> After i migrated to Puppet5 it throws error.
>
> $header="LD_LIBRARY_PATH=$destdir:\$LD_LIBRARY_PATH\n\nexport
> LD_LIBRARY_PATH\n"
> $content = inline_template('<%= header+"\n"+ports.map {|port|


You want @header in an ERB - this changed in puppet 4 I think.
Earlier you just referred to the variable name.

If you instead want to, you could switch to using EPP and
modify the syntax slightly (use $ instead of @) and slight change
in how the lambda given is written.

Best,

- henrik

> memcache_command+" -m "+memory_per_instance+" -p "+port+"
> &"}.join("\n")+"\n" %>')
> file { "$destdir/startmemcached.sh":
>     ensure => file,
>     owner => $title,
>     group => $title,
>     mode => '0744',
>     content => inline_template($content),
> }
>
> Error:
> Error: Could not retrieve catalog from remote server: Error 500 on
> SERVER: Server Error: Evaluation Error: Error while evaluating a
> Resource Statement, Evaluation Error: Error while evaluating a Function
> Call, Failed to parse inline template: undefined local variable or
> method `header' for #<Puppet::Parser::TemplateWrapper:0x5f6a0cd8> (file:
> /home/sas/in2_puppet/environments/production/modules/pkg/manifests/memcache/installmemcache.pp,
> line: 45, column: 12) (file:
> /home/sas/in2_puppet/environments/production/modules/in2/manifests/memcache/common.pp,
> line: 13) on node
>
>
> Can you help me on this.
>
> Regards,
> Suresh
>


--

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

Henrik Lindberg

unread,
Jul 9, 2018, 1:15:58 PM7/9/18
to puppet...@googlegroups.com
On 2018-07-09 19:06, Henrik Lindberg wrote:
> On 2018-07-09 18:12, Suresh P wrote:
>> Hi,
>>
>> I used following code in puppet3.8.x,  it worked well.
>>
>> After i migrated to Puppet5 it throws error.
>>
>> $header="LD_LIBRARY_PATH=$destdir:\$LD_LIBRARY_PATH\n\nexport
>> LD_LIBRARY_PATH\n"
>> $content = inline_template('<%= header+"\n"+ports.map {|port|
>
>
> You want @header in an ERB - this changed in puppet 4 I think.
> Earlier you just referred to the variable name.
>
> If you instead want to, you could switch to using EPP and
> modify the syntax slightly (use $ instead of @) and slight change
> in how the lambda given is written.
>
> Best,
>
> - henrik
>
>> memcache_command+" -m "+memory_per_instance+" -p "+port+"
>> &"}.join("\n")+"\n" %>')
>> file { "$destdir/startmemcached.sh":
>>      ensure => file,
>>      owner => $title,
>>      group => $title,
>>      mode => '0744',
>>      content => inline_template($content),

That is also wrong, you have already called inline_template, so $content
contains the result of the template.

- henrik

Henrik Lindberg

unread,
Jul 9, 2018, 1:29:16 PM7/9/18
to puppet...@googlegroups.com
On 2018-07-09 18:12, Suresh P wrote:
> Hi,
>
> I used following code in puppet3.8.x,  it worked well.
>
> After i migrated to Puppet5 it throws error.
>
> $header="LD_LIBRARY_PATH=$destdir:\$LD_LIBRARY_PATH\n\nexport
> LD_LIBRARY_PATH\n"
> $content = inline_template('<%= header+"\n"+ports.map {|port|
> memcache_command+" -m "+memory_per_instance+" -p "+port+"
> &"}.join("\n")+"\n" %>')
> file { "$destdir/startmemcached.sh":
>     ensure => file,
>     owner => $title,
>     group => $title,
>     mode => '0744',
>     content => inline_template($content),
> }
>

You need neither inline_template nor inline_epp - you can do that
transformation directly in puppet. (Untested rewrite - pardon typos):

$header = "LD_LIBRARY_PATH=$destdir:\$LD_LIBRARY_PATH\n\nexport
LD_LIBRARY_PATH\n"
$format = "${memcache_command} -m ${memory_per_instance} -p %s &"
$entries = $ports.map |$port| { sprintf($format, $port) }.join("\n")

file { "$destdir/startmemcached.sh":
ensure => file,
owner => $title,
group => $title,
mode => '0744',
content => "${header}\n${entries}\n"
}

Hope that is of value,
Best,
- henrik
Reply all
Reply to author
Forward
0 new messages