Hi I''m quite new to the art of writing puppet manifest, but the more I see, the more I like it :-) I''m trying to write a djbdns dnscache module. dnscache configuration is spread in several files, for instance the ip addresses allowed to query the cache each have a file in dnscache/root/ip/ whose filename is the address. I''m trying to automate the creations of those files with puppet, but it seems to be impossible to use arrays of files like this: $clients = [ "10.10.10.10", "10.10.10.11" ] file { $clients: name => "/tmp/${name}", content => "\n" } My obvious intent is to create two files from the two IP address I give. Unfortunately this fails with: info: /File[10.10.10.10]: Adding aliases "" err: Could not create 10.10.10.11: Object /tmp/ already has alias /tmp/ err: Object /tmp/ already has alias /tmp/ This just means to me that ${name} doesn''t contain yet the resource name... And since puppet language is quite limited (you can''t really manipulate arrays), I can''t concatenate the path to the array member directly... Any idea on how I could rewrite the aforementioned puppet snippet? Should I write a my own puppet resource type ? And another question: If I have the following manifest snippet: file { "/tmp/dir1": ensure => directory, mode => 3755; "/tmp/dir1/file2": content => "foobar\n"; } Am I sure puppet will first manage /tmp/dir1 *before* file2, or do I need to specify a "before" in the file2 definition ? Thanks, -- Brice Figureau Days of Wonder
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Saturday 10 November 2007, Brice Figureau wrote:> Hi > > I''m quite new to the art of writing puppet manifest, but the more I see, > the more I like it :-) > > I''m trying to write a djbdns dnscache module. > > dnscache configuration is spread in several files, for instance the ip > addresses allowed to query the cache each have a file in dnscache/root/ip/ > whose filename is the address. > > I''m trying to automate the creations of those files with puppet, but it > seems to be impossible to use arrays of files like this: > > $clients = [ "10.10.10.10", "10.10.10.11" ] > file { > $clients: > name => "/tmp/${name}", > content => "\n" > } > > My obvious intent is to create two files from the two IP address I give. > Unfortunately this fails with: > > info: /File[10.10.10.10]: Adding aliases "" > err: Could not create 10.10.10.11: Object /tmp/ already has alias /tmp/ > err: Object /tmp/ already has alias /tmp/ > > This just means to me that ${name} doesn''t contain yet the resource name... > And since puppet language is quite limited (you can''t really manipulate > arrays), I can''t concatenate the path to the array member directly... > > Any idea on how I could rewrite the aforementioned puppet snippet? > Should I write a my own puppet resource type ?You don''t have to go that far. A simple define will do: define dnscache::client() { file { "/somepath/${name}": ensure => present } } dnscache::client{ $clients: } You might want to add a bit boilerplate to keep "/somepath" clean by overlaying a recursive, purging, empty directory, like I do that in my modules_dir[1] define.> And another question: > If I have the following manifest snippet: > > file { > "/tmp/dir1": ensure => directory, mode => 3755; > "/tmp/dir1/file2": content => "foobar\n"; > } > > Am I sure puppet will first manage /tmp/dir1 *before* file2, or do I need > to specify a "before" in the file2 definition ?Yes, this relationship will be specified automatically. You can run puppetd with --debug to see a definite list of autorequires done on a given configuration. Regards, David [1] See http://reductivelabs.com/trac/puppet/wiki/CompleteConfiguration - -- The primary freedom of open source is not the freedom from cost, but the free- dom to shape software to do what you want. This freedom is /never/ exercised without cost, but is available /at all/ only by accepting the very different costs associated with open source, costs not in money, but in time and effort. - -- http://www.schierer.org/~luke/log/20070710-1129/on-forks-and-forking -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFHNdYf/Pp1N6Uzh0URAiM+AJ9kTWviVkFMKDA/ms2jzhgbvNPNxgCfScGG 7CZkBcDF/QrYIf77oS1oK+s=rJWj -----END PGP SIGNATURE-----
Hi David, Thanks for your answer, On Sat, November 10, 2007 17:02, David Schmitt wrote:> On Saturday 10 November 2007, Brice Figureau wrote: >> I''m quite new to the art of writing puppet manifest, but the more I see, >> the more I like it :-) >> >> I''m trying to write a djbdns dnscache module. >> >> dnscache configuration is spread in several files, for instance the ip >> addresses allowed to query the cache each have a file in >> dnscache/root/ip/ >> whose filename is the address. >> >> I''m trying to automate the creations of those files with puppet, but it >> seems to be impossible to use arrays of files like this: >> >> $clients = [ "10.10.10.10", "10.10.10.11" ] >> file { >> $clients: >> name => "/tmp/${name}", >> content => "\n" >> } >> >> My obvious intent is to create two files from the two IP address I give. >> Unfortunately this fails with: >> >> info: /File[10.10.10.10]: Adding aliases "" >> err: Could not create 10.10.10.11: Object /tmp/ already has alias /tmp/ >> err: Object /tmp/ already has alias /tmp/ >> >> This just means to me that ${name} doesn''t contain yet the resource >> name... >> And since puppet language is quite limited (you can''t really manipulate >> arrays), I can''t concatenate the path to the array member directly... >> >> Any idea on how I could rewrite the aforementioned puppet snippet? >> Should I write a my own puppet resource type ? > > You don''t have to go that far. A simple define will do: > > define dnscache::client() { > file { "/somepath/${name}": ensure => present } > } > > dnscache::client{ $clients: }Yes, I finally came to this scheme by myself before seeing your answer :-) On a side note, one thing I think is missing in puppet is the way to pass some resources to other resources like OOP object references... Something along the line of djbdns::cache { "mycache": <some parameters> } djbdns::clients { [ "1.1.1.1", "2.2.2.2" ] : dnscache => Djbdns::cache["mycache"] } When I first started with puppet a few days ago, I naively thought you could use resource references like that with the following example: class important_group { group { "devl": .... } } class admin_users { include important_group user { "brice": uid => 1000, group => Group["devl"] } } But this doesn''t work :-(> You might want to add a bit boilerplate to keep "/somepath" clean by > overlaying a recursive, purging, empty directory, like I do that in my > modules_dir[1] define.Thanks for the idea, I''ll throw an eye to your modules. -- Brice Figureau Days of Wonder