inline_template private method `gets' called for false:FalseClass

64 views
Skip to first unread message

beyonddc...@gmail.com

unread,
Oct 28, 2013, 12:43:29 PM10/28/13
to puppet...@googlegroups.com
Hi,

I am new to Ruby ERB and inline_template.  Can anyone spot what's wrong with this inline_template?

            $moddedContent = inline_template("<%= puts gets(nil).gsub(/one two three/,\"\") /tmp/blah %>")
            exec {
                "/bin/echo '${moddedContent}' > /tmp/blah" :
            }

When I try to apply it, I got the following error.
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse inline template: private method `gets' called for false:FalseClass at foo.pp:33 on node testnode

Thanks!

David

jcbollinger

unread,
Oct 29, 2013, 10:33:10 AM10/29/13
to puppet...@googlegroups.com

The purpose of an ERB template is to generate strings consisting of zero or more static parts and one or more dynamic parts.  They are otherwise a poor vehicle for embedding general-purpose Ruby code in your manifests.  In particular, you do not normally want to perform explicit I/O in a template.  You certainly don't want to perform I/O to or from the standard streams, as these should not be connected/open when the template is evaluated.  It's not clear to me whether the I/O you are doing is your actual objective (in which case a template is the wrong tool -- use generate() or a custom function instead) or whether it's just your attempt at implementing what you're really after.

Also, it is essential to understand that all Puppet DSL functions, including inline_template(), are executed on the master during catalog compilation, whereas resources, including Execs, are applied to client nodes. As such, if a DSL function drops a file on the local file system, resources cannot normally expected to consume that file because their local file system at application time is normally a different one.

Here's a trivial example of how an inline template might be used:

$foo = 'one two three four five'
$moddedContent = inline_template("<%= @foo.gsub(/one two three/,'') %>")
notify { 'inline_template demo':
  message => "The modified content is $moddedContent"
}
# Yields "The modified content is  four five"

Of course, an experienced Puppeteer would never do that particular job via inline_template(), because the regsubst() function can more clearly, succinctly, and cheaply express the same thing:

$moddedContent = regsubst($foo, 'one two three', '')


John
Reply all
Reply to author
Forward
0 new messages