Hi Everyone, Is it possible to use File directive only if some software is installed, otherwise do nothing? For example: file { "/tmp/puppet-nginx-init.sh": ensure => "present", owner => "root", group => "root", mode => 0755, source => "puppet://$puppetserver/modules/nginx/puppet-nginx-init.sh", # only if nginx is installed } Thank you! -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Hi Roman, you can check for a defined package resource if defined(Package[''nginx'']) { file { …… } } In this case the file resource will only be managed if the package resource has been defined. This does not mean, that the package has been installed successfully! For this option you have to add require => Package[''nginx''], to your file resource. hth, Martin On Jun 20, 2013, at 3:06 PM, Roman Alekseev <rs.alekseev@gmail.com> wrote:> Hi Everyone, > > Is it possible to use File directive only if some software is installed, otherwise do nothing? > For example: > > file { "/tmp/puppet-nginx-init.sh": > ensure => "present", > owner => "root", > group => "root", > mode => 0755, > source => "puppet://$puppetserver/modules/nginx/puppet-nginx-init.sh", > # only if nginx is installed > > } > > Thank you! > > -- > 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+unsubscribe@googlegroups.com. > To post to this group, send email to puppet-users@googlegroups.com. > Visit this group at http://groups.google.com/group/puppet-users. > For more options, visit https://groups.google.com/groups/opt_out. > >-- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
On 20.06.2013 17:46, Martin Alfke wrote:> this case the file resource will only be managed if the package resource has been defined. > This does not mean, that the package has been installed successfully! > For this option you have to add > require => Package[''nginx''], > to your file resource.Thank you your solutions is great! What about a facter something like this: # nginx.rb Facter.add("nginx") do setcode do Facter::Util::Resolution.exec(''/usr/bin/dpkg -l | /bin/grep -c nginx'') end end Thanks -- Kind regards, R. Alekseev -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
On 20 June 2013 14:49, Roman Alekseev <rs.alekseev@gmail.com> wrote:> > What about a facter something like this: > > # nginx.rb > > Facter.add("nginx") do > setcode do > Facter::Util::Resolution.exec(**''/usr/bin/dpkg -l | /bin/grep -c > nginx'') > end > end > >A fact for something like that seems a bit over the top. Is there a reason you are not managing the package using Puppet? Martin''s 2nd solution is far more Puppet-like and is unlikely to cause any head-scratching/confusion compared to your fact-based approach. Regards, Matt. -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
Is the module below correct? class nginx { if defined(Package[''nginx'']) { file { "/tmp/puppet-nginx.sh": ensure => "present", owner => "root", group => "root", mode => 0755, source => "puppet://$puppetserver/modules/nginx/puppet-nginx.sh", require => Package[''nginx''], } } -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
On 21 June 2013 07:04, Roman Alekseev <rs.alekseev@gmail.com> wrote:> Is the module below correct? > > class nginx { > > if defined(Package[''nginx'']) { > > file { "/tmp/puppet-nginx.sh": > > ensure => "present", > owner => "root", > group => "root", > mode => 0755, > source => > "puppet://$puppetserver/modules/nginx/puppet-nginx.sh", > > require => Package[''nginx''], > } > > } >The ''if defined()'' is not required at all and, if I understand recent discussions correctly, will lead to parse-order issues with your manifests. Basically, without that in there, the rest of it says "Install a file containing a copy of puppet-nginx.sh from the puppet server, but only if the nginx package is installed", which I think is what you''re after. See http://docs.puppetlabs.com/learning/ordering.html#packagefileservice for a good example of the common ''package, file, service'' idiom. Regards, Matt.> -- > 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+unsubscribe@googlegroups.com. > To post to this group, send email to puppet-users@googlegroups.com. > Visit this group at http://groups.google.com/group/puppet-users. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.
On Friday, June 21, 2013 1:04:36 AM UTC-5, Roman Alekseev wrote:> > Is the module below correct? > > class nginx { > > if defined(Package[''nginx'']) { > file { "/tmp/puppet-nginx.sh": > ensure => "present", > owner => "root", > group => "root", > mode => 0755, > source => > "puppet://$puppetserver/modules/nginx/puppet-nginx.sh", > require => Package[''nginx''], > } > > }Do not use defined(). Ever. There are two possible approaches here. The better is to determine based on node facts and/or external data whether nginx is *supposed* to be installed, and then to include class ''nginx'' only if so. In that case, the class might look like this: class nginx { # ensure the package installed package { ''nginx'': ensure => ''installed'' } # ensure the target file in place file { "/tmp/puppet-nginx.sh": ensure => ''file'', owner => ''root'', group => ''root'', mode => 0755, source => ''puppet:///modules/nginx/puppet-nginx.sh'' } } Note that if the file were supposed to replace one that the package provides (e.g. a config file) then you would also want to declare a relationship between the two to ensure that the package was managed before the file. One way to declare that would be: Package[''nginx''] => File[''/tmp/puppet-nginx.sh''] Note also that a fully-featured nginx module would probably manage the nginx configuration file and service as well. The alternative is what you are attempting: to detect whether nginx is already installed, and to manage the target file only in that case. For that, you do indeed want a custom fact to communicate to the master whether nginx is installed. If you do it that way, then as Matthew said, the defined() doesn''t do anything useful for you. In fact, it is more likely harmful than useful. Instead, you might write your class like this: class nginx { if $::nginx_is_installed == ''true'' { # ensure the target file in place file { "/tmp/puppet-nginx.sh": ensure => ''file'', owner => ''root'', group => ''root'', mode => 0755, source => ''puppet:///modules/nginx/puppet-nginx.sh'' } } } You can apply that to all nodes. Do note that all facts are strings. You custom fact must be written that way, and any test you perform on the fact value must accommodate it. John -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users. For more options, visit https://groups.google.com/groups/opt_out.