I know I brought this up in a different post a while ago in as a different question. Whats the best way to locate a configuration file from a ruby manifest? I''m tring to load a yaml for database properties but so far the only way to make it work is if I explicitly define a path either manually or looking up a specific module path. The latter being an issue if the module name is not known when it is installed. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Tue, Sep 6, 2011 at 7:24 AM, Matt <mjblack@gmail.com> wrote:> I know I brought this up in a different post a while ago in as a > different question. > > Whats the best way to locate a configuration file from a ruby > manifest? I''m tring to load a yaml for database properties but so far > the only way to make it work is if I explicitly define a path either > manually or looking up a specific module path. The latter being an > issue if the module name is not known when it is installed.Not sure if there''s an exposed API that''s more suitable. What are you using currently for find the file in a specific module? I''m not sure why the module name is unknown, unless you are planning to allow someone to change it during installation. Similar to puppet manifests you should be able to use the puppet variable $module_name if you are on 2.6+. Since the files directory is intended for file service, the best place for the config is probably the templates directory. The following should return the fully qualified filepath to the config file in the module templates dir: Puppet::Parser::Files.find_template_in_module("#{scope.lookup_var(''module_name'')}/config.yaml") Thanks, Nan -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
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. On Sep 6, 11:56 am, Nan Liu <n...@puppetlabs.com> wrote:> On Tue, Sep 6, 2011 at 7:24 AM, Matt <mjbl...@gmail.com> wrote: > > I know I brought this up in a different post a while ago in as a > > different question. > > > Whats the best way to locate a configuration file from a ruby > > manifest? I''m tring to load a yaml for database properties but so far > > the only way to make it work is if I explicitly define a path either > > manually or looking up a specific module path. The latter being an > > issue if the module name is not known when it is installed. > > Not sure if there''s an exposed API that''s more suitable. What are you > using currently for find the file in a specific module? > > I''m not sure why the module name is unknown, unless you are planning > to allow someone to change it during installation. Similar to puppet > manifests you should be able to use the puppet variable $module_name > if you are on 2.6+. Since the files directory is intended for file > service, the best place for the config is probably the templates > directory. The following should return the fully qualified filepath to > the config file in the module templates dir: > > Puppet::Parser::Files.find_template_in_module("#{scope.lookup_var(''module_name'')}/config.yaml") > > Thanks, > > Nan-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
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 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
I am using 2.6.6, when I try your example I get a empty string back, I tried with ''module_name'' and the actual name of the module and both return an empty string. On Sep 6, 12:27 pm, Nan Liu <n...@puppetlabs.com> wrote:> On Tue, Sep 6, 2011 at 9:08 AM, Matt <mjbl...@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-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.