FAQ

Given the manifest:

$a = 1
$b = 1 + 0
$c = 1.1
$d = 1.1 + 0
$result = inline_template("
a <%= @a.class %> <%= @a %>
b <%= @b.class %> <%= @b %>
c <%= @c.class %> <%= @c %>
d <%= @d.class %> <%= @d %>
")
notify {
$result:
}


The output is:
a String 1
b Fixnum 1
c String 1.1
d Float 1.1


Is this working as intended?

How can I identify number types within the template without adding "+ 0" on
the manifest? I'm aware that it's not a good idea to duck-type on templates
but I'm still wondering.


--
Claudio

--
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 puppet-users+unsubscribe@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Claudio at Jun 25, 2013 at 4:39 pm
    I forgot to clarify that this was tested on versions 3.2.1 and 3.2.2.
    On Tuesday, June 25, 2013 1:06:21 PM UTC-3, Claudio wrote:


    Given the manifest:
    $a = 1
    $b = 1 + 0
    $c = 1.1
    $d = 1.1 + 0
    $result = inline_template("
    a <%= @a.class %> <%= @a %>
    b <%= @b.class %> <%= @b %>
    c <%= @c.class %> <%= @c %>
    d <%= @d.class %> <%= @d %>
    ")
    notify {
    $result:
    }


    The output is:
    a String 1
    b Fixnum 1
    c String 1.1
    d Float 1.1


    Is this working as intended?

    How can I identify number types within the template without adding "+ 0"
    on the manifest? I'm aware that it's not a good idea to duck-type on
    templates but I'm still wondering.


    --
    Claudio
    --
    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 puppet-users+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Jcbollinger at Jun 26, 2013 at 1:04 pm

    On Tuesday, June 25, 2013 11:06:21 AM UTC-5, Claudio wrote:

    Given the manifest:
    $a = 1
    $b = 1 + 0
    $c = 1.1
    $d = 1.1 + 0
    $result = inline_template("
    a <%= @a.class %> <%= @a %>
    b <%= @b.class %> <%= @b %>
    c <%= @c.class %> <%= @c %>
    d <%= @d.class %> <%= @d %>
    ")
    notify {
    $result:
    }


    The output is:
    a String 1
    b Fixnum 1
    c String 1.1
    d Float 1.1


    Is this working as intended?

    I think so. Puppet DSL does not require most string literals to be quoted,
    so it can distinguish numeric-form strings from actual numbers only by how
    they are produced or used. I think it reasonable for Puppet to treat all
    values as strings except where it has specific reason to do otherwise.
    That's not the only possible approach, but I think it's probably the best
    fit for Puppet.


    How can I identify number types within the template without adding "+ 0"
    on the manifest? I'm aware that it's not a good idea to duck-type on
    templates but I'm still wondering.
    It depends on what you mean by that. Apparently it's not about identifying
    whether Puppet is treating the value as numeric, so I guess it's about
    whether the value is numeric in form. Perhaps you could do something along
    these lines:

    <%
       begin
         num = Float(@maybe_num)
         # It can be interpreted as a number
       rescue
         # It's not numeric
       end
      %>

    Really, though, this should not be necessary. The DSL code calling the
    template should know how to use it appropriately (else it has no business
    using it at all).


    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 puppet-users+unsubscribe@googlegroups.com.
    To post to this group, send email to puppet-users@googlegroups.com.
    Visit this group at http://groups.google.com/group/puppet-users.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedJun 25, '13 at 4:09p
activeJun 26, '13 at 1:04p
posts3
users2
websitepuppetlabs.com

2 users in discussion

Claudio: 2 posts Jcbollinger: 1 post

People

Translate

site design / logo © 2021 Grokbase