Ask Your Question
0

Access variable from other manifest

asked 2016-12-13 02:51:29 -0500

snuff1987 gravatar image

updated 2016-12-13 05:32:38 -0500

domcleal gravatar image

Hi, I'm trying to write my own module ...Right now it is only a experimental and consists from 2 manifests...

init.pp

class ntp (
$var = $ntp::params::ip1,
)
{
file { '/tmp/module.conf':
  path    => '/tmp/module.conf',
  ensure  => file,
  content => "$var",
}
}

params.pp

class ntp::params {
$ip1 = "8.8.8.8",
}

I just want to print the value stored in manifest params.pp in variable ip1 to the file /tmp/module.conf, but I always get no result in the file.. if I change variable $var to some string it appears in the file...Could you help me, what am I doing wrong?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-12-13 05:35:03 -0500

domcleal gravatar image

Change the ntp class definition to add an inherits ntp::params, this ensures that it loads the ntp::params class to fill in the default parameters.

class ntp (
  $var = $ntp::params::ip1,
) inherits ntp::params
{
  ...
}

Please note that you should prefer storing data in modules with Puppet 4 which has advantages over the "params" pattern. See Quick intro to module data for more information.

edit flag offensive delete link more
0

answered 2016-12-14 00:06:15 -0500

snuff1987 gravatar image

updated 2016-12-14 00:08:23 -0500

Thank you very much, finally it helped..I tried inherits thing as well but I had some mistakes with commas in variables.. Now it works fine.. I found out that in manifests between { } brackets there is no need for commas in variables declaration..

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2016-12-13 02:51:29 -0500

Seen: 86 times

Last updated: Dec 14 '16