Discussion:
[Puppet Users] variables created with generate() function have a newline when used in a template
bowlby
2010-12-26 11:45:04 UTC
Permalink
I have this in nodes.pp

$puppetmaster_fqdn = generate("/usr/bin/facter","fqdn")

and this in a template

http://<%= puppetmaster_fqdn %>:8080

When puppet runs, this is the result:

http://puppet.home
:8080

Anybody any clue to whats causing this? I've tried -%>
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet-***@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
R.I.Pienaar
2010-12-26 11:53:55 UTC
Permalink
----- Original Message -----
Post by bowlby
I have this in nodes.pp
$puppetmaster_fqdn = generate("/usr/bin/facter","fqdn")
the output from this command has a new line in it
Post by bowlby
http://<%= puppetmaster_fqdn %>:8080
<%= puppetmaster_fqdn.chomp %>
--
R.I.Pienaar
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet-***@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Daniel Pittman
2010-12-26 11:54:29 UTC
Permalink
Post by bowlby
I have this in nodes.pp
$puppetmaster_fqdn = generate("/usr/bin/facter","fqdn")
and this in a template
http://<%= puppetmaster_fqdn %>:8080
http://puppet.home
:8080
Anybody any clue to whats causing this? I've tried -%>
I suspect that -%> only eats whitespace outside the bracket, not
inside. Anyhow, you can make this do the right thing using a tiny bit
of ruby: <%= puppetmaster_fqdn.chomp %>

Regards,
Daniel
--
✣ Daniel Pittman            ✉ ***@rimspace.net            ☎ +61 401 155 707
              ♽ made with 100 percent post-consumer electrons
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet-***@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
bowlby
2010-12-26 12:43:26 UTC
Permalink
Thanks, both of you! That solved it.

Merry Christmas (for what's left of it...)
Post by Daniel Pittman
Post by bowlby
I have this in nodes.pp
$puppetmaster_fqdn = generate("/usr/bin/facter","fqdn")
and this in a template
http://<%= puppetmaster_fqdn %>:8080
http://puppet.home
:8080
Anybody any clue to whats causing this? I've tried -%>
I suspect that -%> only eats whitespace outside the bracket, not
inside.  Anyhow, you can make this do the right thing using a tiny bit
of ruby:  <%= puppetmaster_fqdn.chomp %>
Regards,
    Daniel
--
              ♽ made with 100 percent post-consumer electrons
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet-***@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Sven vd
2012-12-13 15:48:44 UTC
Permalink
This works when using the variable inside a template.

But I want to use the variable in an Exec command. How to remove the
newline here? .chomp does not seem to work here.

THanks
Post by bowlby
Thanks, both of you! That solved it.
Merry Christmas (for what's left of it...)
Post by Daniel Pittman
Post by bowlby
I have this in nodes.pp
$puppetmaster_fqdn = generate("/usr/bin/facter","fqdn")
and this in a template
http://<%= puppetmaster_fqdn %>:8080
http://puppet.home
:8080
Anybody any clue to whats causing this? I've tried -%>
I suspect that -%> only eats whitespace outside the bracket, not
inside. Anyhow, you can make this do the right thing using a tiny bit
of ruby: <%= puppetmaster_fqdn.chomp %>
Regards,
Daniel
--
155 707
Post by Daniel Pittman
♜ made with 100 percent post-consumer electrons
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/AECI05CiIRYJ.
To post to this group, send email to puppet-***@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
jcbollinger
2012-12-14 14:17:24 UTC
Permalink
Post by Sven vd
This works when using the variable inside a template.
But I want to use the variable in an Exec command. How to remove the
newline here? .chomp does not seem to work here.
No, it wouldn't. The 'chomp' is a method of Ruby's String class. It works
in the embedded Ruby context in a template, but it is not part of the
Puppet DSL, so it does not work for ordinary variable interpolation.

The underlying problem is that the generate() command you are using is
outputting a trailing newline that gets incorporated into the resulting
value. That's not too surprising, as it is good form for programs (such as
whatever external command you are running) to terminate their output with a
newline.

You have two main options:

1. Modify the command in some way or filter its output to remove the
newline before it reaches Puppet
2. Remove the newline inside Puppet

I leave you to figure out (1) on your own. You have multiple approaches
available for (2). The easiest built into Puppet is to use a template,
probably via the inline_template() function:

$result_line = generate('my command')
$result = inline_template('<%= @result_line.chomp %>')

That's a little ugly, though. If you have or are willing to install
Puppetlabs' "stdlib" add-on module, then it provides a chomp() function in
Puppet. With that, you could replace the second line above with:

$result = chomp($result_line)

Note well that Puppet variables can only be assigned values once each.
That's why my examples use two variables ($result_line and $result).


John
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/UGPbUpMwetIJ.
To post to this group, send email to puppet-***@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Sven vd
2012-12-14 17:07:30 UTC
Permalink
Thanks for your complete answer! I used the inline_template method which is
good enough for me
Post by jcbollinger
Post by Sven vd
This works when using the variable inside a template.
But I want to use the variable in an Exec command. How to remove the
newline here? .chomp does not seem to work here.
No, it wouldn't. The 'chomp' is a method of Ruby's String class. It
works in the embedded Ruby context in a template, but it is not part of the
Puppet DSL, so it does not work for ordinary variable interpolation.
The underlying problem is that the generate() command you are using is
outputting a trailing newline that gets incorporated into the resulting
value. That's not too surprising, as it is good form for programs (such as
whatever external command you are running) to terminate their output with a
newline.
1. Modify the command in some way or filter its output to remove the
newline before it reaches Puppet
2. Remove the newline inside Puppet
I leave you to figure out (1) on your own. You have multiple approaches
available for (2). The easiest built into Puppet is to use a template,
$result_line = generate('my command')
That's a little ugly, though. If you have or are willing to install
Puppetlabs' "stdlib" add-on module, then it provides a chomp() function in
$result = chomp($result_line)
Note well that Puppet variables can only be assigned values once each.
That's why my examples use two variables ($result_line and $result).
John
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/bsVEopGUj2QJ.
To post to this group, send email to puppet-***@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Loading...