Re: [Puppet Users] Re: config files for ruby dsl manifests

Nan Liu
2011-09-06T16:27:35Z

On Tue, Sep 6, 2011 at 9:08 AM, Matt <mjblack@gmail.com>
wrote:
> I''m trying to write a ruby dsl manifest that pulls data from a
> database. The issue I''m trying to overcome is I dont want to have
to
> hardcode the location of the db configuration. If I set it at the
> init.pp level the configuration it will be picked up as top scope and
> dumped to the facts, and also be visible to other things like
> mcollective.
>
> The piece of code you provided did not work for me, it looks like
I''m
> not able to pull back the module name from scope it seems.

What version of Puppet?

Here''s a full example with file path:

# init.rb
hostclass :custom do
  pmod  = scope.lookupvar(''module_name'')
  fpath =
Puppet::Parser::Files.find_template_in_module("#{pmod}/config.yaml")
  notify pmod, :message => pmod
  notify fpath, :message => fpath
end

Directory layout in modules:

└── custom
   ├── manifests
   │   └── init.rb
   ├── templates
   │   └── config.yaml
   └── tests
       └── init.pp

Sample output:
notice: custom
notice: /Stage[main]/Custom/Notify[custom]/message: defined
''message''
as ''custom''
notice: /Users/nan/.puppet/modules/custom/templates/config.yaml
notice:
/Stage[main]/Custom/Notify[/Users/nan/.puppet/modules/custom/templates/config.yaml]/message:
defined ''message'' as
''/Users/nan/.puppet/modules/custom/templates/config.yaml''
notice: Finished catalog run in 0.04 seconds

Thanks,

Nan