Re: [Puppet Users] environmentpath in manifest
Hi Martin, Il giorno 13/mag/2016, alle ore 09:36, Martin Alfkeha scritto: > The Ruby part must be a function - like in the example you provided in your > first email. > You can then use the function inside your manifest. > > Functions are always executed on the Master. After a couple of try, i understood it. for anyone looking at the same solution, my code: manifest: $masterenvpath = print_environmentpath() $path = "${masterenvpath}/${::environment}/modules/braveconf/files/puppet/puppet.conf-${::hostname}" if ( file_exists ("${path}") == 1 ) { function: lib/puppet/parser/functions/print_environmentpath.rb require"puppet" module Puppet::Parser::Functions newfunction(:print_environmentpath, :type => :rvalue) do |args| Puppet.initialize_settings unless Puppet[:environmentpath] path = Puppet[:environmentpath] if File.exists?(path) path else nil end end end Thank you very much Martin! Daniele -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/C86CAE7A-3FE7-4C9E-94D1-D96E59C3C0B7%40retaggio.net. For more options, visit https://groups.google.com/d/optout. signature.asc Description: Message signed with OpenPGP using GPGMail
Re: [Puppet Users] environmentpath in manifest
Hi Michael, there are 2 possibilities: 1) i have not got what you mean. 2) you have not got what i mean. To better explain: your suggestion is to look over a fact in the agents. my needed environmentpath variable is the master one. i need to check over the existence of a file, but i want to have the full path as variables. in example: $confdir in puppet.conf, but master section, not agent one. which of the 2 cases? :) Thanks in any case! Daniele Il giorno 13/mag/2016, alle ore 14:18, Michael Wattersha scritto: > You may need to create a custom fact to determine the environment when > the agent runs. For example, here's a > custom fact that reads the environment from a file. > > Facter.add("environment") do >setcode do > Facter::Util::Resolution.exec('/bin/cat /usr/local/etc/environment') >end > end > > Your site manifest can also be set to update the file contents when it runs. > > > > On Monday, May 9, 2016 at 9:45:38 AM UTC-4, Daniele Palumbo wrote: > Hi, > > i need to check if a file exists on the puppet master. > > No big deal: > http://stackoverflow.com/questions/18784329/how-to-test-for-existence-of-a-file-on-the-puppet-master > > So i made: > -- > cat ./modules/braveconf/lib/puppet/parser/functions/file_exists.rb > require"puppet" > module Puppet::Parser::Functions > newfunction(:file_exists, :type => :rvalue) do |args| > if File.exists?(args[0]) > return 1 > else > return 0 > end > end > end > -- > > Now, my problem is about path. > > Since i have environmentpath, as seen is > puppet config print environmentpath --section master --environment > development > /etc/puppetlabs/code/environments > > I would like to use, in the manifest: > -- > if ( file_exists > ("${::environmentpath}/${::environment}/modules/module/files/configfile-${::hostname}") > == 1 ) { > -- > > But ${::environmentpath} is empty. > > How can i manage this topic, avoiding to hardcode > /etc/puppetlabs/code/environments in the code? > Is there a way to get variable from puppet master config? > > Thanks, > Daniele > > > > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/9b1f21ea-a95c-4bd3-a44d-8ba85b32a636%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/D6034FF4-1791-4F8C-A75A-9DF42758A4AE%40retaggio.net. For more options, visit https://groups.google.com/d/optout. signature.asc Description: Message signed with OpenPGP using GPGMail
Re: [Puppet Users] environmentpath in manifest
You may need to create a custom fact to determine the environment when the agent runs. For example, here's a custom fact that reads the environment from a file. Facter.add("environment") do setcode do Facter::Util::Resolution.exec('/bin/cat /usr/local/etc/environment') end end Your site manifest can also be set to update the file contents when it runs. On 05/08/2016 05:36 PM, Daniele Palumbo wrote: Hi, i need to check if a file exists on the puppet master. No big deal: http://stackoverflow.com/questions/18784329/how-to-test-for-existence-of-a-file-on-the-puppet-master So i made: -- cat ./modules/braveconf/lib/puppet/parser/functions/file_exists.rb require"puppet" module Puppet::Parser::Functions newfunction(:file_exists, :type => :rvalue) do |args| if File.exists?(args[0]) return 1 else return 0 end end end -- Now, my problem is about path. Since i have environmentpath, as seen is puppet config print environmentpath --section master --environment development /etc/puppetlabs/code/environments I would like to use, in the manifest: -- if ( file_exists ("${::environmentpath}/${::environment}/modules/module/files/configfile-${::hostname}") == 1 ) { -- But ${::environmentpath} is empty. How can i manage this topic, avoiding to hardcode /etc/puppetlabs/code/environments in the code? Is there a way to get variable from puppet master config? Thanks, Daniele -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/2704bbaf-2a0f-f8ed-c81f-954fd95dccb1%40watters.ws. For more options, visit https://groups.google.com/d/optout.
Re: [Puppet Users] environmentpath in manifest
Hi Daniele, On 13 May 2016, at 02:13, Daniele Palumbowrote: > Il giorno 12/mag/2016, alle ore 10:19, Martin Alfke ha > scritto: >> You might want to access the Puppet settings: >> >> Puppet.initialize_settings unless Puppet[:confdir] >> >> and then check for the environmentpath setting. > > > Hi Martin, > > Thank you very much for your hint. > > But I am not able to understand how to write it. > How can I interlock between this ruby code and the manifest? The Ruby part must be a function - like in the example you provided in your first email. You can then use the function inside your manifest. Functions are always executed on the Master. Best, Martin > > Sorry if this is a FAQ question :) > Do you have some link or example to understand how this should work? > > Thank you very much, > Daniele > > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/0329312A-9935-4B1F-A2CF-19E0E4D484BB%40retaggio.net. > For more options, visit https://groups.google.com/d/optout. -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/5CBD144D-3CDC-4CD2-9526-A0EBFBF08D6F%40gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [Puppet Users] environmentpath in manifest
Il giorno 12/mag/2016, alle ore 10:19, Martin Alfkeha scritto: > You might want to access the Puppet settings: > > Puppet.initialize_settings unless Puppet[:confdir] > > and then check for the environmentpath setting. Hi Martin, Thank you very much for your hint. But I am not able to understand how to write it. How can I interlock between this ruby code and the manifest? Sorry if this is a FAQ question :) Do you have some link or example to understand how this should work? Thank you very much, Daniele -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/0329312A-9935-4B1F-A2CF-19E0E4D484BB%40retaggio.net. For more options, visit https://groups.google.com/d/optout.
Re: [Puppet Users] environmentpath in manifest
Hi Daniele, On 08 May 2016, at 23:36, Daniele Palumbowrote: > Hi, > > i need to check if a file exists on the puppet master. > > No big deal: > http://stackoverflow.com/questions/18784329/how-to-test-for-existence-of-a-file-on-the-puppet-master > > So i made: > -- > cat ./modules/braveconf/lib/puppet/parser/functions/file_exists.rb > require"puppet" > module Puppet::Parser::Functions >newfunction(:file_exists, :type => :rvalue) do |args| >if File.exists?(args[0]) > return 1 >else > return 0 >end > end > end > -- > > Now, my problem is about path. > > Since i have environmentpath, as seen is > puppet config print environmentpath --section master --environment > development > /etc/puppetlabs/code/environments > > I would like to use, in the manifest: > -- > if ( file_exists > ("${::environmentpath}/${::environment}/modules/module/files/configfile-${::hostname}") > == 1 ) { > -- > > But ${::environmentpath} is empty. You might want to access the Puppet settings: Puppet.initialize_settings unless Puppet[:confdir] and then check for the environmentpath setting. > > How can i manage this topic, avoiding to hardcode > /etc/puppetlabs/code/environments in the code? > Is there a way to get variable from puppet master config? > > Thanks, > Daniele > > > -- > 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+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/6429762B-377B-4B9D-B8B4-526859465283%40retaggio.net. > For more options, visit https://groups.google.com/d/optout. -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/97001652-424C-4CD5-AF9B-02CA8EFF2317%40gmail.com. For more options, visit https://groups.google.com/d/optout.