FAQ
i expect the file /tmp/conftest content will be "mymaster" not default "HM"
on node bm ,but fail,anyone can help?

here my init.pp

class hadoop {
         require hadoop::params
          file { "/tmp/conftest":
                 ensure => 'file',
                 content => "$hadoop::params::master",
         }
}
here my node.pp

node 'default' {
         include hadoop
}
node 'bm' inherits 'default' {
         $hadoop::params::master = 'mymaster'
}

here is my params.pp

class hadoop::params {
            $master = $::hostname ? {
                 default => 'HM',
         }
}

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

  • Rahul Khengare at Sep 24, 2013 at 12:14 pm
    hi ch Huang,
        Here in this case you have to use parameterised class concept. Refer
    http://docs.puppetlabs.com/guides/parameterized_classes.html for
    parameterised classes concept.
    You can restructure your manifests to solve your issue.

    Refer following manifests,

    *init.pp file*
    here we pass the *master* parameter to class and inherits params class.
    class hadoop (
        $master = $hadoop::params::master,
      ) inherits hadoop::params {

         file { "/tmp/conftest":
             ensure => 'file',
             content => "${master}",
         }
    }

    *node.pp*
    node 'default' {
         class {"hadoop":
           # pass the master parameter to hadoop class it will override the
    value present in the params file,
           # if we are not passing the master parameter then it take default
    value present in the params.pp file
              master => 'mymaster',
         }
    }
    node 'bm' inherits 'default' {
    }

    *params.pp*
    class hadoop::params {
           $master = $::hostname ? {
             default => 'HM',
           }
    }

    Hope this would help.


    Thanks and Regards,
    Rahul Khengare,
    NTT DATA OSS Center, Pune, India.

    On Tuesday, September 24, 2013 11:51:29 AM UTC+5:30, ch huang wrote:

    i expect the file /tmp/conftest content will be "mymaster" not default
    "HM" on node bm ,but fail,anyone can help?

    here my init.pp

    class hadoop {
    require hadoop::params
    file { "/tmp/conftest":
    ensure => 'file',
    content => "$hadoop::params::master",
    }
    }
    here my node.pp

    node 'default' {
    include hadoop
    }
    node 'bm' inherits 'default' {
    $hadoop::params::master = 'mymaster'
    }

    here is my params.pp

    class hadoop::params {
    $master = $::hostname ? {
    default => 'HM',
    }
    }
    --
    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 Sep 24, 2013 at 2:54 pm

    On Tuesday, September 24, 2013 7:14:52 AM UTC-5, Rahul Khengare wrote:
    hi ch Huang,
    Here in this case you have to use parameterised class concept. Refer
    http://docs.puppetlabs.com/guides/parameterized_classes.html for
    parameterised classes concept.
    You can restructure your manifests to solve your issue.

    Refer following manifests, [...]
    Do note, however, that although Rahul's code should produce the expected
    result for node 'bm', it does so by changing the result for *every* node.
    You don't need class parameters for that. That could be remedied by a
    variation that drops node inheritance. Keep your original declaration for
    the default node, and change node 'bm' to not inherit anything. Make
    Rahul's parameterized-style declaration of class 'hadoop' the complete
    contents of node 'bm's declaration. That should give you the desired
    result for node 'bm' without changing the original result on other nodes.


    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.
  • Jcbollinger at Sep 24, 2013 at 2:47 pm

    On Tuesday, September 24, 2013 1:21:29 AM UTC-5, ch huang wrote:
    i expect the file /tmp/conftest content will be "mymaster" not default
    "HM" on node bm ,but fail,anyone can help?
    You cannot assign values to non-local variables. Even if you could, you
    would not get your desired result because node inheritance does not work
    the way you hope. The best solution is to feed data to your class from an
    external source. Class parameters such as Rahul describes are a popular
    vehicle for doing that, though you can also just load data directly via a
    data-access function. Chief among such functions in modern Puppet is
    hiera().

    For small-scale testing purposes, however, you can also just bake the data
    into your classes. Indeed, it looks like you are set up for that already.
    For example, if you make this change

    class hadoop::params {
         $master = $::hostname ? {
             'bm' => 'mymaster',
             default => 'HM',
         }
    }

    then you can remove node 'bm' altogether, and you will get the expected
    result.


    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
postedSep 24, '13 at 8:23a
activeSep 24, '13 at 2:54p
posts4
users3
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase