How can I express the following in puppet? $http_conf = "/etc/http/conf/httpd.conf" $vhosts_conf = "/etc/http/conf/vhosts.conf" @files = ("$httpd_conf", "$vhosts_conf") foreach f (@files) { file { "$f": owner => root, group => root, mode => 664, source => "puppet://$server/apache/$f", } service { ''httpd'': ensure => true, subscribe => File["$f"] } } I just want to manage a group of files from the same directory, same perms, etc. and have the service restart once, if one or both of the files change. Thanks, Kent -- "It may be true that the law cannot make a man love me, but it can stop him from lynching me, and I think that''s pretty important." - Martin Luther King Jr.
On 2/14/07, Kenton Brede <kbrede@gmail.com> wrote:> How can I express the following in puppet? > > $http_conf = "/etc/http/conf/httpd.conf" > $vhosts_conf = "/etc/http/conf/vhosts.conf"$filestomanage = ["/etc/http/conf/httpd.conf", "/etc/http/conf/vhosts.conf"]> file { "$f": > owner => root, group => root, mode => 664, > source => "puppet://$server/apache/$f", > }file { $filestomanage: owner => ... etc. }> service { ''httpd'': > ensure => true, > subscribe => File["$f"] > }Uhm... not sure about this one... Might work with a File[$filestomanage], but haven''t tested that. Someone more knowledgable should answer that. -- Gegroet, Tim
On Feb 14, 2007, at 5:02 PM, Tim Stoop wrote:> >> service { ''httpd'': >> ensure => true, >> subscribe => File["$f"] >> } > > Uhm... not sure about this one... Might work with a > File[$filestomanage], but haven''t tested that. Someone more > knowledgable should answer that.That does not yet work but hopefully will soon. The best way to do it is something like a wrapper of the normal remotefile definition: define apachefile(...) { remotefile { $name: ..., notify => Service[http] } } -- A child can go only so far in life without potty training. It is not mere coincidence that six of the last seven presidents were potty trained, not to mention nearly half of the nation''s state legislators. -- Dave Barry --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
On 2/14/07, Luke Kanies <luke@madstop.com> wrote:> On Feb 14, 2007, at 5:02 PM, Tim Stoop wrote: > > > >> service { ''httpd'': > >> ensure => true, > >> subscribe => File["$f"] > >> } > > > > Uhm... not sure about this one... Might work with a > > File[$filestomanage], but haven''t tested that. Someone more > > knowledgable should answer that. > > That does not yet work but hopefully will soon. The best way to do > it is something like a wrapper of the normal remotefile definition: > > define apachefile(...) { > remotefile { $name: ..., notify => Service[http] } > }OK, I feel like an idiot here. After reading the docs several times I''m still not able to do anything but write very simple manifests. I''m not a programmer but I can write shell scripts and hack perl a bit. I know what an array is, I know what a hash is, I know: flow, iteration, etc. For some reason I''m not able to grasp these things with puppet so far. Would it help if I learned Ruby? It seems like I read somewhere the puppet language is influenced by Ruby. In the example above is "define apachefile(...)" where an array is defined? This throws a syntax error but as an example: define apachefile(["/etc/httpd/conf/httpd.conf", "/etc/httpd/conf/vhosts.conf"]) { remotefile { $name: source => "puppet://$server/apache/$name", } mode => ''644'' } To me the above code would say, define an array of files [...httpd.conf, ...vhost.conf], then iterate through the array pulling the files with the variable "$name" and perform the actions of "source" and "mode." Obviously I''m thinking about this wrong but what is the right way to interpret? define apachefile(...) { remotefile { $name: ..., notify => Service[http] } } Thanks, Kent -- "It may be true that the law cannot make a man love me, but it can stop him from lynching me, and I think that''s pretty important." - Martin Luther King Jr.
Hi Kenton, On 2/15/07, Kenton Brede <kbrede@gmail.com> wrote:> > OK, I feel like an idiot here.There''s no reason too. Your questions are all perfectly valid, we just cut some corners in our explanation :) Kudos to you for pointing that out :)> After reading the docs several times > I''m still not able to do anything but write very simple manifests. > I''m not a programmer but I can write shell scripts and hack perl a > bit. I know what an array is, I know what a hash is, I know: flow, > iteration, etc. For some reason I''m not able to grasp these things > with puppet so far. Would it help if I learned Ruby? It seems like I > read somewhere the puppet language is influenced by Ruby.Not sure if it would help, but the puppet language isn''t very complicated, once you know the basics. Actually, I think at the moment, there are only basics, so let''s dive into those :) In the example above is "define apachefile(...)" where an array is> defined? This throws a syntax error but as an example: > > define apachefile(["/etc/httpd/conf/httpd.conf", > "/etc/httpd/conf/vhosts.conf"]) { > remotefile { $name: > source => "puppet://$server/apache/$name", > } mode => ''644'' > }No, we define arrays outside of definitions. So a simple: $httpconffiles = ["httpd.conf", "vhosts.conf"] will suffice. Note how I leave out the complete path. This is just a convenience to myself, since the paths for files for apache config will always be in the same place, I''m adding that path just once to the definition. You know, us sysadmins should take a better look at programmers: Less typing == better. So we''re trying to create macros that will help us "not type". That is, "not type more than is absolutely necessary". I''m sure this is no news to you, but I''m stating it anyway, so this email reads nicer :) Next, we''re making a definition. A definition is somethink like a function or a macro in other languages. It takes arguments that we define ourselves. When I look at the definition you tried yourself, I think you meant to make something like this: define apachefile { file { $name: source => "puppet://puppet/files/apache/$name", owner => root, group => root, mode => 644, ensure => file, backup => false, recurse => false, notify => Service[''http''], } } These definitions are done quite often, so we (= my company, not puppet users in general, although I think more people do it) put them in a separate file. We call the file "util.pp" and import it in our site.pp. You don''t need to define the array here, only the define apachefile {} will suffice. Now in the class definition, we can do something like: class apacheserver { $httpconffile = ["httpd.conf", "vhosts.conf"] apachefile { $httpconffile: } } (Don''t forget the colon!) And include it for the node you want it on. Easy as that. Some good reads for this: - For all those options that file can have: < http://reductivelabs.com/projects/puppet/reference/typedocs.html> - About definitions (also called components): <http://www.reductivelabs.com/trac/puppet/wiki/LanguageStructures#Components>Good hunting, puppeteer! -- Gegroet, Tim _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
On Feb 15, 2007, at 9:01 AM, Kenton Brede wrote:> > OK, I feel like an idiot here.I agree with Tim here: If the documentation does not provide sufficient enlightenment, it is the fault of the docs, not of the reader. If Tim''s explanation is not sufficient, please say so and we can go into it in more detail. The only thing that I would add is that when you specify a resource with an array for the name (as both Tim and I recommended), it''s worth noting that Puppet creates a new resource for each item in the array. Thus, you can be sure that $name is set to a string, not an array, inside the definition. -- The death rate on Earth is: .... (computing) .... One per person. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
On 2/15/07, Tim Stoop <tim.stoop@gmail.com> wrote:> Hi Kenton, > > On 2/15/07, Kenton Brede <kbrede@gmail.com > wrote: > > OK, I feel like an idiot here. > > There''s no reason too. Your questions are all perfectly valid, we just cut > some corners in our explanation :) Kudos to you for pointing that out :) > > > After reading the docs several times > > I''m still not able to do anything but write very simple manifests. > > I''m not a programmer but I can write shell scripts and hack perl a > > bit. I know what an array is, I know what a hash is, I know: flow, > > iteration, etc. For some reason I''m not able to grasp these things > > with puppet so far. Would it help if I learned Ruby? It seems like I > > read somewhere the puppet language is influenced by Ruby. > > > > Not sure if it would help, but the puppet language isn''t very complicated, > once you know the basics. Actually, I think at the moment, there are only > basics, so let''s dive into those :) > > > > In the example above is "define apachefile(...)" where an array is > > defined? This throws a syntax error but as an example: > > > > define apachefile(["/etc/httpd/conf/httpd.conf", > > "/etc/httpd/conf/vhosts.conf"]) { > > remotefile { $name: > > source => > "puppet://$server/apache/$name", > > } mode => ''644'' > > } > > No, we define arrays outside of definitions. So a simple: > > $httpconffiles = ["httpd.conf", "vhosts.conf"] > > will suffice. Note how I leave out the complete path. This is just a > convenience to myself, since the paths for files for apache config will > always be in the same place, I''m adding that path just once to the > definition. You know, us sysadmins should take a better look at programmers: > Less typing == better. So we''re trying to create macros that will help us > "not type". That is, "not type more than is absolutely necessary". I''m sure > this is no news to you, but I''m stating it anyway, so this email reads nicer > :) > > Next, we''re making a definition. A definition is somethink like a function > or a macro in other languages. It takes arguments that we define ourselves. > When I look at the definition you tried yourself, I think you meant to make > something like this: > > define apachefile { > file { $name: > source => "puppet://puppet/files/apache/$name", > owner => root, > group => root, > mode => 644, > ensure => file, > backup => false, > recurse => false, > notify => Service[''http''], > } > } > > These definitions are done quite often, so we (= my company, not puppet > users in general, although I think more people do it) put them in a separate > file. We call the file " util.pp" and import it in our site.pp. You don''t > need to define the array here, only the define apachefile {} will suffice. > > Now in the class definition, we can do something like: > > class apacheserver { > $httpconffile = ["httpd.conf", "vhosts.conf"] > > apachefile { $httpconffile: } > } > > (Don''t forget the colon!) > > And include it for the node you want it on. Easy as that. > > Some good reads for this: > > - For all those options that file can have: > <http://reductivelabs.com/projects/puppet/reference/typedocs.html > > > > - About definitions (also called components): > <http://www.reductivelabs.com/trac/puppet/wiki/LanguageStructures#Components > >Thanks to both you and Luke. Bits are starting to make more sense. Just to round this off, let me post what seems to be working. The "$server" variable I''ve defined in site.pp since it should be global for all. If there''s anything that seems out of whack, let me know. I can see calling "service httpd" like I have might be a problem, if I end up with more than one definition that includes apache, but I suspect flow control would solve that one. Defining "$conf_dir" wasn''t entirely necessary but I wanted to play a little and see how things work. define apache_files { $conf_dir = ''/etc/httpd/conf'' file { "$conf_dir/$name": source => "puppet://$server/apache/$name", owner => root, group => root, mode => 644, notify => Service[''httpd''], } } service { ''httpd'': ensure => true, } class apache_server { $apache_conf_files = ["httpd.conf", "vhosts.conf"] apache_files { $apache_conf_files: } } Kent -- "It may be true that the law cannot make a man love me, but it can stop him from lynching me, and I think that''s pretty important." - Martin Luther King Jr.
Hi Kenton, On 2/15/07, Kenton Brede <kbrede@gmail.com> wrote:> Just to round this off, let me post what seems to be working. The > "$server" variable I''ve defined in site.pp since it should be global > for all. If there''s anything that seems out of whack, let me know. I > can see calling "service httpd" like I have might be a problem, if I > end up with more than one definition that includes apache, but I > suspect flow control would solve that one.Which flow control is that? :) You can''t have a duplicate name with a single type, so be wary of that. But for smaller setups, this wouldn''t be a problem. (Or at least a bit beyond the basics imho :))> service { ''httpd'': > ensure => true, > }Although this is perfectly correct, for clarities sake, I''d use "running" instead of "true". We should spy on programmers for some of their methods, but let''s ignore the perl guys :)> class apache_server { > $apache_conf_files = ["httpd.conf", "vhosts.conf"] > apache_files { $apache_conf_files: } > }Great! Also remember that in this case, it''s probably not worth the trouble of writing a whole definition, since you could''ve written it out for those two files easily. But we use a configfile component for managing 100+ config files (... eventually) and that''s just easy. You can find it here: <http://people.redhat.com/dlutter/puppet-app.html> Saves me a whole lot of typing! -- Gegroet, Tim
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday 15 February 2007 21:43, Kenton Brede wrote:> define apache_files { > $conf_dir = ''/etc/httpd/conf'' > file { "$conf_dir/$name": > source => "puppet://$server/apache/$name", > owner => root, group => root, mode => 644, > notify => Service[''httpd''], > } > } > > service { ''httpd'': > ensure => true, > } > > class apache_server { > $apache_conf_files = ["httpd.conf", "vhosts.conf"] > apache_files { $apache_conf_files: } > }You might want to put the service{httpd: ...} definition into your apache_server class. Since classes can be included multiple times without conflicting (they just count as one) that would prevent unintended conflicts. Regards, David - -- - - hallo... wie gehts heute? - - *hust* gut *rotz* *keuch* - - gott sei dank kommunizieren wir über ein septisches medium ;) -- Matthias Leeb, Uni f. angewandte Kunst, 2005-02-15 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFF1YHU/Pp1N6Uzh0URAvVqAKCTCtfi4JevSC4uLeBS/Qi4EbqaXgCdH0yJ 0GMeRr91LUmaOHeRenCTzLE=yN4m -----END PGP SIGNATURE-----
On 2/16/07, David Schmitt <david@schmitt.edv-bus.at> wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Thursday 15 February 2007 21:43, Kenton Brede wrote: > > > define apache_files { > > $conf_dir = ''/etc/httpd/conf'' > > file { "$conf_dir/$name": > > source => "puppet://$server/apache/$name", > > owner => root, group => root, mode => 644, > > notify => Service[''httpd''], > > } > > } > > > > service { ''httpd'': > > ensure => true, > > } > > > > class apache_server { > > $apache_conf_files = ["httpd.conf", "vhosts.conf"] > > apache_files { $apache_conf_files: } > > } > > You might want to put the service{httpd: ...} definition into your > apache_server class. Since classes can be included multiple times without > conflicting (they just count as one) that would prevent unintended conflicts.Thanks David. That worked well. Kent -- "It may be true that the law cannot make a man love me, but it can stop him from lynching me, and I think that''s pretty important." - Martin Luther King Jr.