Gabriel Filion
2011-Jan-31 17:06 UTC
[Puppet Users] accessing puppet config variables inside a manifest
Hello, I''m currently using a module named "common" which is based off of David Schmitt''s work. I''m having issues with it in OpenBSD, and the reason is that the directory created to contain module-specific files is hardcoded to /var/lib/pupppet/modules. Now, I could easily special-case the path for OpenBSD and the other OSes that don''t keep their $vardir under this directory, but I was wondering if it was possible to access variables from puppet.conf into the manifests. If it could be possible, it would be more elegant to use the $vardir value directly. I''ve done a quick test to print (notify{}) the value of $vardir and it''s empty. Do you guys know of a way I could access this value within the module''s manifests? -- Gabriel Filion -- 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.
Nan Liu
2011-Jan-31 18:09 UTC
Re: [Puppet Users] accessing puppet config variables inside a manifest
On Mon, Jan 31, 2011 at 9:06 AM, Gabriel Filion <lelutin@gmail.com> wrote:> Hello, > > I''m currently using a module named "common" which is based off of David > Schmitt''s work. > > I''m having issues with it in OpenBSD, and the reason is that the > directory created to contain module-specific files is hardcoded to > /var/lib/pupppet/modules. > > Now, I could easily special-case the path for OpenBSD and the other OSes > that don''t keep their $vardir under this directory, but I was wondering > if it was possible to access variables from puppet.conf into the manifests. > If it could be possible, it would be more elegant to use the $vardir > value directly. > > I''ve done a quick test to print (notify{}) the value of $vardir and it''s > empty. Do you guys know of a way I could access this value within the > module''s manifests?Yeah, that would make manifests a lot more flexible. Here''s a function that should work for this purpose and potentially other puppet configuration variables as well: # puppet_vardir.rb module Puppet::Parser::Functions newfunction(:puppet_vardir, :type => :rvalue) do Puppet[:vardir] end end # vardir.pp notice (puppet_vardir()) # puppet apply vardir.pp notice: Scope(Class[main]): /var/lib/puppet # puppet apply vardir.pp --vardir=/tmp/ notice: Scope(Class[main]): /tmp 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.
donavan
2011-Feb-01 09:10 UTC
[Puppet Users] Re: accessing puppet config variables inside a manifest
On Jan 31, 10:09 am, Nan Liu <n...@puppetlabs.com> wrote:> On Mon, Jan 31, 2011 at 9:06 AM, Gabriel Filion <lelu...@gmail.com> wrote: > Yeah, that would make manifests a lot more flexible. Here''s a function > that should work for this purpose and potentially other puppet > configuration variables as well:You can also wedge this in to an inline template like: inline_template(''<%= Puppet.settings[:vardir] %>'') The first (large) caveat is that this checks the setting on the puppet master. I''m not sure if you want the value from the client. If so I suspect you''d need to create a facter fact that parsed your puppet.conf. I''m also not sure on the best way to access Puppet settings. It''s been a while since I''ve done this off hand. I know (previously?) settings could be accessed differently based on their section(s) in puppet.conf. [master] and [main] may have different settings, for example. -- 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.
R.I.Pienaar
2011-Feb-01 09:16 UTC
Re: [Puppet Users] Re: accessing puppet config variables inside a manifest
----- Original Message -----> On Jan 31, 10:09 am, Nan Liu <n...@puppetlabs.com> wrote: > > On Mon, Jan 31, 2011 at 9:06 AM, Gabriel Filion <lelu...@gmail.com> > > wrote: > > Yeah, that would make manifests a lot more flexible. Here''s a > > function > > that should work for this purpose and potentially other puppet > > configuration variables as well: > > You can also wedge this in to an inline template like: > inline_template(''<%= Puppet.settings[:vardir] %>'') > > The first (large) caveat is that this checks the setting on the puppet > master. I''m not sure if you want the value from the client. If so I > suspect you''d need to create a facter fact that parsed your > puppet.conf. > > I''m also not sure on the best way to access Puppet settings. It''s been > a while since I''ve done this off hand. I know (previously?) settings > could be accessed differently based on their section(s) in > puppet.conf. [master] and [main] may have different settings, for > example. >Since 2.6.0 you can just do notice($settings::vardir) -- 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.
Gabriel Filion
2011-Feb-03 08:20 UTC
Re: [Puppet Users] accessing puppet config variables inside a manifest
On 11-01-31 01:09 PM, Nan Liu wrote:>> I''ve done a quick test to print (notify{}) the value of $vardir and it''s >> > empty. Do you guys know of a way I could access this value within the >> > module''s manifests? > Yeah, that would make manifests a lot more flexible. Here''s a function > that should work for this purpose and potentially other puppet > configuration variables as well: > > # puppet_vardir.rb > module Puppet::Parser::Functions > newfunction(:puppet_vardir, :type => :rvalue) do > Puppet[:vardir] > end > endhmm, that''s interestingly very simple. I would personally use a fact instead of a function, but now that I know the ruby part to fetch the config value, writing a fact shouldn''t be too difficult. thanks, -- Gabriel Filion -- 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.
Gabriel Filion
2011-Feb-03 08:35 UTC
Re: [Puppet Users] Re: accessing puppet config variables inside a manifest
On 11-02-01 04:16 AM, R.I.Pienaar wrote:> Since 2.6.0 you can just do notice($settings::vardir)oh .. I''ve just tried it out and it works. hurray for 2.6, then! :) and, I''ll also keep Nan Liu''s suggestion in mind for 0.25.x Thanks to everyone for the feedback! -- Gabriel Filion -- 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.