I''m trying to create a virtual host file only if the document root directory exists. It doesn''t look like puppet is seeing the require metaparameter. Currently, the file is being created whether or not the document root directory exists. What is the best way to currently do this? I''m trying to create a file called site1.conf in /apps/apache/conf.d only if /var/www/html/site1 directory exists. file { "/apps/apache/conf.d/site1.conf": ensure => present, content => template("apache/virtual_host.erb"), notify => Service["jboss_apache"], require => File["/var/www/html/site1"] } --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Your require is actually creating the site1 directory if it doesn''t exist (unless your file def. for that directory has ensure => absent). I think you want to go the other way and ensure that the site1.conf is created by the definition for the site1 directory. In other words, put a require for the site1.conf in the file definition for the site1 directory. On Nov 20, 3:05 pm, Hang Chan <hangch...@gmail.com> wrote:> I''m trying to create a virtual host file only if the document root > directory exists. It doesn''t look like puppet is seeing the require > metaparameter. Currently, the file is being created whether or not > the document root directory exists. What is the best way to currently > do this? > > I''m trying to create a file called site1.conf in /apps/apache/conf.d > only if /var/www/html/site1 directory exists. > > file { "/apps/apache/conf.d/site1.conf": > ensure => present, > content => template("apache/virtual_host.erb"), > notify => Service["jboss_apache"], > require => File["/var/www/html/site1"] > }--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Andrew Shafer
2008-Nov-20 20:46 UTC
[Puppet Users] Re: create a file only if directory exists
Hang, The ''require'' is going to look for a resource definition and make sure that the current resource is applied later. ''require'' establishes explicit order, not conditional logic. Also... Please don''t take what I''m about to write the wrong way. Are you familiar with the concept of ''code smells'' or ''anti-patterns''? When I see people trying to set up logic like that I personally think it is a Puppet smell. Why? Because at the end of the day, once you get it all working, you don''t have a way to know where site1 exists without sshing to all the boxes and looking for that directory. What if you have some site1 specific logic, do you just keep adding if logic on a directory existing? I personally recommend you reframe your strategy to declare site1 specific resources and then declare the hosts that serve site1. Whenever possible declare, I think it will pay off in the long term. Regards, Andrew On Thu, Nov 20, 2008 at 1:05 PM, Hang Chan <hangchan1@gmail.com> wrote:> > I''m trying to create a virtual host file only if the document root > directory exists. It doesn''t look like puppet is seeing the require > metaparameter. Currently, the file is being created whether or not > the document root directory exists. What is the best way to currently > do this? > > I''m trying to create a file called site1.conf in /apps/apache/conf.d > only if /var/www/html/site1 directory exists. > > file { "/apps/apache/conf.d/site1.conf": > ensure => present, > content => template("apache/virtual_host.erb"), > notify => Service["jboss_apache"], > require => File["/var/www/html/site1"] > } > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 just hardcoding it to debug it, actual configuation isn''t like this. I tried it the other way too and it''s still creating the file. file { "/apps/apache/conf.d/site1.conf": ensure => present, content => template("apache/virtual_host.erb"), notify => Service["jboss_apache"], # require => File["/var/www/html/site1"] } file { "/var/www/html/site1": require => File["/apps/apache/conf.d/site1.conf"] } Is the way to approach this to use the exec type and onlyif resource? On Nov 20, 3:36 pm, joe <lava...@gmail.com> wrote:> Your require is actually creating the site1 directory if it doesn''t > exist (unless your file def. for that directory has ensure => absent). > I think you want to go the other way and ensure that the site1.conf is > created by the definition for the site1 directory. In other words, > put a require for the site1.conf in the file definition for the site1 > directory. > > On Nov 20, 3:05 pm, Hang Chan <hangch...@gmail.com> wrote: > > > I''m trying to create a virtual host file only if the document root > > directory exists. It doesn''t look like puppet is seeing the require > > metaparameter. Currently, the file is being created whether or not > > the document root directory exists. What is the best way to currently > > do this? > > > I''m trying to create a file called site1.conf in /apps/apache/conf.d > > only if /var/www/html/site1 directory exists. > > > file { "/apps/apache/conf.d/site1.conf": > > ensure => present, > > content => template("apache/virtual_host.erb"), > > notify => Service["jboss_apache"], > > require => File["/var/www/html/site1"] > > }--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Andrew Shafer
2008-Nov-20 22:22 UTC
[Puppet Users] Re: create a file only if directory exists
hardcoding what? what are you trying to debug? Read what ''require'' does. Require is not a conditional branch, it makes ordering explicit. Exec with onlyif is one way you could get the behavior, or an if condition with a custom fact would. There might be another way too. I believe all of those idioms are going to be clumsy and hard to manage. What is your end goal? On Thu, Nov 20, 2008 at 2:34 PM, Hang Chan <hangchan1@gmail.com> wrote:> > I''m just hardcoding it to debug it, actual configuation isn''t like > this. > > I tried it the other way too and it''s still creating the file. > > file { "/apps/apache/conf.d/site1.conf": > ensure => present, > content => template("apache/virtual_host.erb"), > notify => Service["jboss_apache"], > # require => File["/var/www/html/site1"] > } > > file { "/var/www/html/site1": > require => File["/apps/apache/conf.d/site1.conf"] > } > > Is the way to approach this to use the exec type and onlyif resource? > > On Nov 20, 3:36 pm, joe <lava...@gmail.com> wrote: > > Your require is actually creating the site1 directory if it doesn''t > > exist (unless your file def. for that directory has ensure => absent). > > I think you want to go the other way and ensure that the site1.conf is > > created by the definition for the site1 directory. In other words, > > put a require for the site1.conf in the file definition for the site1 > > directory. > > > > On Nov 20, 3:05 pm, Hang Chan <hangch...@gmail.com> wrote: > > > > > I''m trying to create a virtual host file only if the document root > > > directory exists. It doesn''t look like puppet is seeing the require > > > metaparameter. Currently, the file is being created whether or not > > > the document root directory exists. What is the best way to currently > > > do this? > > > > > I''m trying to create a file called site1.conf in /apps/apache/conf.d > > > only if /var/www/html/site1 directory exists. > > > > > file { "/apps/apache/conf.d/site1.conf": > > > ensure => present, > > > content => template("apache/virtual_host.erb"), > > > notify => Service["jboss_apache"], > > > require => File["/var/www/html/site1"] > > > } > > >--~--~---------~--~----~------------~-------~--~----~ 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 create a virtual host file only if the document root directory exists. I could care less what method I use as long as it works. Please let me know the best way to do this. I realize now that require won''t accomplish what I want. I don''t need puppet to create the /var/www/html/site1 directory as that is created manually. Want puppet to check If the /var/www/html/ site1 directory exists and create the /apps/apache/conf.d/site1.conf file if it does. Also need puppet to delete the /apps/apache/conf.d/ site1.conf file if the /var/www/html/site1 directory no longer exists. On Nov 20, 5:22 pm, "Andrew Shafer" <and...@reductivelabs.com> wrote:> hardcoding what? what are you trying to debug? > > Read what ''require'' does. Require is not a conditional branch, it makes > ordering explicit. > > Exec with onlyif is one way you could get the behavior, or an if condition > with a custom fact would. There might be another way too. > > I believe all of those idioms are going to be clumsy and hard to manage. > > What is your end goal? > > On Thu, Nov 20, 2008 at 2:34 PM, Hang Chan <hangch...@gmail.com> wrote: > > > I''m just hardcoding it to debug it, actual configuation isn''t like > > this. > > > I tried it the other way too and it''s still creating the file. > > > file { "/apps/apache/conf.d/site1.conf": > > ensure => present, > > content => template("apache/virtual_host.erb"), > > notify => Service["jboss_apache"], > > # require => File["/var/www/html/site1"] > > } > > > file { "/var/www/html/site1": > > require => File["/apps/apache/conf.d/site1.conf"] > > } > > > Is the way to approach this to use the exec type and onlyif resource? > > > On Nov 20, 3:36 pm, joe <lava...@gmail.com> wrote: > > > Your require is actually creating the site1 directory if it doesn''t > > > exist (unless your file def. for that directory has ensure => absent). > > > I think you want to go the other way and ensure that the site1.conf is > > > created by the definition for the site1 directory. In other words, > > > put a require for the site1.conf in the file definition for the site1 > > > directory. > > > > On Nov 20, 3:05 pm, Hang Chan <hangch...@gmail.com> wrote: > > > > > I''m trying to create a virtual host file only if the document root > > > > directory exists. It doesn''t look like puppet is seeing the require > > > > metaparameter. Currently, the file is being created whether or not > > > > the document root directory exists. What is the best way to currently > > > > do this? > > > > > I''m trying to create a file called site1.conf in /apps/apache/conf.d > > > > only if /var/www/html/site1 directory exists. > > > > > file { "/apps/apache/conf.d/site1.conf": > > > > ensure => present, > > > > content => template("apache/virtual_host.erb"), > > > > notify => Service["jboss_apache"], > > > > require => File["/var/www/html/site1"] > > > > }--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mike Renfro
2008-Nov-21 14:46 UTC
[Puppet Users] Re: create a file only if directory exists
Hang Chan wrote:> I don''t need puppet to create the /var/www/html/site1 directory as > that is created manually. Want puppet to check If the /var/www/html/ > site1 directory exists and create the /apps/apache/conf.d/site1.conf > file if it does. Also need puppet to delete the /apps/apache/conf.d/ > site1.conf file if the /var/www/html/site1 directory no longer exists.You might consider making a puppet definition that would both create the site1 directory, and then copy the site1.conf afterwards. If you want something already written, then David Schmitt''s Apache module at http://git.black.co.at/?p=module-apache;a=tree;h=refs/heads/production;hb=refs/heads/production should handle all of what you''re asking for. Either use it as-is, or look through his manifests for how his definitions to enable and disable a site programmatically. Some of his methods are Debian-specific, so they might not translate entirely into your environment. -- Mike Renfro / R&D Engineer, Center for Manufacturing Research, 931 372-3601 / Tennessee Technological University -- renfro@tntech.edu --~--~---------~--~----~------------~-------~--~----~ 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 looked through his definitions and it only checks if the proper packages exists before setting up his configuration files. I need to check if the directory exists as a condition. I don''t want to create the directory if it doesn''t, as it is created manually right now and needs to stay that way for awhile. Eventually it will all be automated in puppet, but haven''t gone that far yet. I just want to do something like this (in bash): if [ -d "/var/www/html/site1" ]; then touch /apps/apache/conf.d/site1.conf exit 0 else echo "directory does not exist" exit 1 fi This seems like a simple thing to do, but for the life of me can''t figure out how to do this in puppet. On Nov 21, 9:46 am, Mike Renfro <ren...@tntech.edu> wrote:> Hang Chan wrote: > > I don''t need puppet to create the /var/www/html/site1 directory as > > that is created manually. Want puppet to check If the /var/www/html/ > > site1 directory exists and create the /apps/apache/conf.d/site1.conf > > file if it does. Also need puppet to delete the /apps/apache/conf.d/ > > site1.conf file if the /var/www/html/site1 directory no longer exists. > > You might consider making a puppet definition that would both create the > site1 directory, and then copy the site1.conf afterwards. If you want > something already written, then David Schmitt''s Apache module athttp://git.black.co.at/?p=module-apache;a=tree;h=refs/heads/productio... > should handle all of what you''re asking for. Either use it as-is, or > look through his manifests for how his definitions to enable and disable > a site programmatically. Some of his methods are Debian-specific, so > they might not translate entirely into your environment. > > -- > Mike Renfro / R&D Engineer, Center for Manufacturing Research, > 931 372-3601 / Tennessee Technological University -- ren...@tntech.edu--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Mike Renfro
2008-Nov-21 16:30 UTC
[Puppet Users] Re: create a file only if directory exists
On 11/21/2008 10:18 AM, Hang Chan wrote:> I looked through his definitions and it only checks if the proper > packages exists before setting up his configuration files.site.pp also includes an apache::site definition that can create or remove a configuration file depending on if you call the definition with ensure => ''present'' (the default), or ensure => ''absent''. That definition could be easily extended to also automatically create or remove the folder you''re worried about.> I need to check if the directory exists as a condition. I don''t want > to create the directory if it doesn''t, as it is created manually > right now and needs to stay that way for awhile.Then you''ll probably have to copy down the configuration file into a separate location, and use an exec to cp it into the proper destination with an onlyif test. -- Mike Renfro / R&D Engineer, Center for Manufacturing Research, 931 372-3601 / Tennessee Technological University --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Then you''ll probably have to copy down the configuration file into a > separate location, and use an exec to cp it into the proper destination > with an onlyif test.That sounds like a good suggestion. Have to stop being so straightforward with my thinking. On Nov 21, 11:30 am, Mike Renfro <ren...@tntech.edu> wrote:> On 11/21/2008 10:18 AM, Hang Chan wrote: > > > I looked through his definitions and it only checks if the proper > > packages exists before setting up his configuration files. > > site.pp also includes an apache::site definition that can create or > remove a configuration file depending on if you call the definition with > ensure => ''present'' (the default), or ensure => ''absent''. That > definition could be easily extended to also automatically create or > remove the folder you''re worried about. > > > I need to check if the directory exists as a condition. I don''t want > > to create the directory if it doesn''t, as it is created manually > > right now and needs to stay that way for awhile. > > Then you''ll probably have to copy down the configuration file into a > separate location, and use an exec to cp it into the proper destination > with an onlyif test. > > -- > Mike Renfro / R&D Engineer, Center for Manufacturing Research, > 931 372-3601 / Tennessee Technological University--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---