Hi, i wanted to know how you handle case when classes or define need to communicate between them. For exemple i got an ftpd define and a apachevhost define. Both need to know the path where the vhost is set and this path is defined by the ftpuser home''s directory. How can i ask information from other define or other classes ? we allready seen that tag are not reliable as they depend on the order the parser read them. For exemple how to say that a define requires another define as a requirement ( i think of the ftpuser define that creates a ftp user account and the ftpdaemon define that is used to configure the ftp daemon and the define that create the apache vhost ,it need the ftpuser to be created before and the ftpuser define need that the ftpdaemon exist before ...). i also tried to make a define inside another define but i cannot. I have seen the syntax xx::yy to acces some data but when is this usable ? What data can be read between part of the recipes ? I see my recipe getting more complex and i am a little lost on how they can interact with each others. Any ideas/hint on this side ? -- Cordialement, Ghislain _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
Luke Kanies
2007-Apr-18 21:42 UTC
Re: dependency and communication between defined classes
On Apr 18, 2007, at 3:45 PM, ADNET Ghislain wrote:> Hi, > > i wanted to know how you handle case when classes or define need to > communicate between them. For exemple i got an ftpd define and a > apachevhost define. Both need to know the path where the vhost is > set and this path is defined by the ftpuser home''s directory. How > can i ask information from other define or other classes ? we > allready seen that tag are not reliable as they depend on the order > the parser read them. > > For exemple how to say that a define requires another define as a > requirement ( i think of the ftpuser define that creates a ftp user > account and the ftpdaemon define that is used to configure the ftp > daemon and the define that create the apache vhost ,it need the > ftpuser to be created before and the ftpuser define need that the > ftpdaemon exist before ...). > > i also tried to make a define inside another define but i cannot. > I have seen the syntax xx::yy to acces some data but when is this > usable ? What data can be read between part of the recipes ?Right now, no such thing exists. Any recommendations on how to do this would be great. -- A cult is a religion with no political power. -- Tom Wolfe --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Blake Barnett
2007-Apr-18 23:21 UTC
Re: dependency and communication between defined classes
On Apr 18, 2007, at 2:42 PM, Luke Kanies wrote:> On Apr 18, 2007, at 3:45 PM, ADNET Ghislain wrote: > >> Hi, >> >> i wanted to know how you handle case when classes or define need to >> communicate between them. For exemple i got an ftpd define and a >> apachevhost define. Both need to know the path where the vhost is >> set and this path is defined by the ftpuser home''s directory. How >> can i ask information from other define or other classes ? we >> allready seen that tag are not reliable as they depend on the order >> the parser read them. >> >> For exemple how to say that a define requires another define as a >> requirement ( i think of the ftpuser define that creates a ftp user >> account and the ftpdaemon define that is used to configure the ftp >> daemon and the define that create the apache vhost ,it need the >> ftpuser to be created before and the ftpuser define need that the >> ftpdaemon exist before ...). >> >> i also tried to make a define inside another define but i cannot. >> I have seen the syntax xx::yy to acces some data but when is this >> usable ? What data can be read between part of the recipes ? > > Right now, no such thing exists. Any recommendations on how to do > this would be great.Doesn''t load order allow this? For example: class conglomeration { define { ... } include class_with_definition_that_uses_variables_from_above_define } -Blake
Luke Kanies
2007-Apr-19 03:03 UTC
Re: dependency and communication between defined classes
On Apr 18, 2007, at 6:21 PM, Blake Barnett wrote:> > Doesn''t load order allow this? For example: > > class conglomeration { > define { ... } > include > class_with_definition_that_uses_variables_from_above_define > }Nope; variables are available to scopes below, but not above or at the same level. In other words, variables set in the conglomeration class are available in both the define and class, but that''s it. -- What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against? --Larry Wall in <1992Aug26.184221.29627@netlabs.com> --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Luke Kanies
2007-Apr-19 18:40 UTC
Re: dependency and communication between defined classes
On Apr 18, 2007, at 3:45 PM, ADNET Ghislain wrote:> Hi, > > i wanted to know how you handle case when classes or define need to > communicate between them. For exemple i got an ftpd define and a > apachevhost define. Both need to know the path where the vhost is > set and this path is defined by the ftpuser home''s directory. How > can i ask information from other define or other classes ? we > allready seen that tag are not reliable as they depend on the order > the parser read them. > > For exemple how to say that a define requires another define as a > requirement ( i think of the ftpuser define that creates a ftp user > account and the ftpdaemon define that is used to configure the ftp > daemon and the define that create the apache vhost ,it need the > ftpuser to be created before and the ftpuser define need that the > ftpdaemon exist before ...). > > i also tried to make a define inside another define but i cannot. > I have seen the syntax xx::yy to acces some data but when is this > usable ? What data can be read between part of the recipes ?After berating myself a bit for having my own language that doesn''t do what people want, I asked myself how hard this would be, and I concluded, not that hard. After thinking about it some to make sure it doesn''t open up any weird holes anywhere, I''ve added the functionality. The following code now works as you''d hope (in svn, of course): class one { $var = value } class one::two { $other = more } class three { include one, one::two $three = $one::two::other exec { "/bin/echo one: $one::var, two: $one::two::other, three: $three": } } include three You cannot (and likely never will be able to) assign to variables in other classes, and you *must* evaluate the class before you try to retrieve its variables (thus the ''include'' in the ''three'' class). This is in changeset 2393: https://reductivelabs.com/trac/puppet/changeset/2393 Comments? -- Always behave like a duck - keep calm and unruffled on the surface but paddle like the devil underneath. -- Jacob Braude --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Luke Kanies
2007-Apr-19 18:53 UTC
Re: dependency and communication between defined classes
On Apr 19, 2007, at 1:40 PM, Luke Kanies wrote:> > After berating myself a bit for having my own language that doesn''t > do what people want, I asked myself how hard this would be, and I > concluded, not that hard. After thinking about it some to make sure > it doesn''t open up any weird holes anywhere, I''ve added the > functionality. The following code now works as you''d hope (in svn, > of course): > > class one { > $var = value > } > > class one::two { > $other = more > } > > class three { > include one, one::two > $three = $one::two::other > exec { "/bin/echo one: $one::var, two: $one::two::other, three: > $three": } > } > include threeYou can also use ''$::var'' to refer to variables in the top-level scope. I realize now that people are going to want references now, because you''re going to want to refer to variables set within a node config, and that''s going to be impossible because this code won''t work: $var = ${$hostname}::variable Hmm. Would that be reasonable to add? Or should we instead make the class ''node'' semi-magical, so that you could say: $var = $node::variable Maybe I should just add a function like ''nodevar'': $var = nodevar(variable) That would correctly look through the tree of node scopes, so that nodes could override values set in parent nodes. Ideas? -- To be positive: To be mistaken at the top of one''s voice. -- Ambrose Bierce --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Blake Barnett
2007-Apr-19 19:21 UTC
Re: dependency and communication between defined classes
On Apr 19, 2007, at 11:53 AM, Luke Kanies wrote:> On Apr 19, 2007, at 1:40 PM, Luke Kanies wrote: >> >> After berating myself a bit for having my own language that doesn''t >> do what people want, I asked myself how hard this would be, and I >> concluded, not that hard. After thinking about it some to make sure >> it doesn''t open up any weird holes anywhere, I''ve added the >> functionality. The following code now works as you''d hope (in svn, >> of course): >> >> class one { >> $var = value >> } >> >> class one::two { >> $other = more >> } >> >> class three { >> include one, one::two >> $three = $one::two::other >> exec { "/bin/echo one: $one::var, two: $one::two::other, three: >> $three": } >> } >> include three > > You can also use ''$::var'' to refer to variables in the top-level > scope. > > I realize now that people are going to want references now, because > you''re going to want to refer to variables set within a node config, > and that''s going to be impossible because this code won''t work: > > $var = ${$hostname}::variable > > Hmm. Would that be reasonable to add? Or should we instead make the > class ''node'' semi-magical, so that you could say: > > $var = $node::variable > > Maybe I should just add a function like ''nodevar'': > > $var = nodevar(variable) > > That would correctly look through the tree of node scopes, so that > nodes could override values set in parent nodes.I like this last one. -Blake
ADNET Ghislain
2007-Apr-19 22:46 UTC
Re: dependency and communication between defined classes
>> Maybe I should just add a function like ''nodevar'': >> >> $var = nodevar(variable) >> >> That would correctly look through the tree of node scopes, so that >> nodes could override values set in parent nodes. >> > > I like this last one. > > -Blakesame here, the others seems...weird in syntax to me :) -- Cordialement, Ghislain _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
ADNET Ghislain
2007-Apr-19 22:59 UTC
Re: dependency and communication between defined classes
> This is in changeset 2393: > > https://reductivelabs.com/trac/puppet/changeset/2393 > > Comments? > >this is a great thing, let me some time to see how i can work my recipe with this feature and i will tell you if i have a comment :) at first i wondered if one::two::$other woudl be easier to read or ${one::two::other} ..humm not sure yet... -- Cordialement, Ghislain _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
Luke Kanies
2007-Apr-20 02:23 UTC
Re: dependency and communication between defined classes
On Apr 19, 2007, at 5:59 PM, ADNET Ghislain wrote:> this is a great thing, let me some time to see how i can work my > recipe with this feature and i will tell you if i have a comment :) > > at first i wondered if one::two::$other woudl be easier to read or $ > {one::two::other} ..humm not sure yet...The first would be much harder to lex -- you wouldn''t know you had a variable until you got to the $. This version was pretty easy to lex, and it''s pretty easy to understand, I think. -- It''s impossible to foresee the consequences of being clever. -- Christopher Strachey --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
ADNET Ghislain
2007-Apr-20 07:34 UTC
Re: dependency and communication between defined classes
would it be also possible to a way to make user defined ''define'' require something in the definition and not in the calling of it ? i mean you can do define test($testme){ file { test: } } test { montest: testme => ''hello'', require => File[''debug''] } but if i want that my define is allways requiring something i cannot (or do not know) how to say : define test($testme){ file { test: } require => File[''debug''] } so that the user do not have to know the internal of the class and put requires on all calls of it as the define take cares of it... same for before, refresh etc... -- Cordialement, Ghislain _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
ADNET Ghislain schrieb:> would it be also possible to a way to make user defined ''define'' > require something in the definition and not in the calling of it ? > > i mean you can do > > define test($testme){ > file { test: } > } > > test { montest: > testme => ''hello'', > require => File[''debug''] > } > > but if i want that my define is allways requiring something i cannot > (or do not know) how to say : > > define test($testme){ > file { test: } > require => File[''debug''] > } > > so that the user do not have to know the internal of the class and put > requires on all calls of it as the define take cares of it... same for > before, refresh etc... > > > ------------------------------------------------------------------------ > > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users >When I understand you correctly you want this, as defines implicitly "require" all described objects: define test($testme, $pathvar){ file { test: } file {''debugfile'': path => "$pathvar" } where $pathvar is just introduced to not break the convention to not use anything but variables in defines. hope i understood your question correctly..
ADNET Ghislain
2007-Apr-20 09:43 UTC
Re: dependency and communication between defined classes
this is not really the same thing as here you create the File[''debugfile''] in your define, what i want is that my define be run AFTER the File[''debugfile''] is processed but this debugfile is NOT created by the define but comes from another part of the recipe. In your solution File[''debugfile''] cannot exist before or you have a duplicate definition issue.> When I understand you correctly you want this, as defines implicitly > "require" all described objects: > > define test($testme, $pathvar){ > file { test: } > > file {''debugfile'': > path => "$pathvar" > } > > where $pathvar is just introduced to not break the convention to not use > anything but variables in defines. > hope i understood your question correctly.. > >-- Cordialement, Ghislain ADNET. AQUEOS. Attention ! Toute demande de support ou commande de domaine par email sera refusée, pour cela utilisez https://support.aqueos.net. Pour tout contact nos coordonnées : http://www.aqueos.com/aqueos-services-informatiques-societe.php Fax: 01.72.70.32.66 _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
You could create the debugfile as a virual resource and create a fixed order in your definition of "test" by using requires. I guess this could get quite ugly in the long run but depending on your actual case I think this could be a temporary solution.. ADNET Ghislain schrieb:> this is not really the same thing as here you create the > File[''debugfile''] in your define, what i want is that my define be run > AFTER the File[''debugfile''] is processed but this debugfile is NOT > created by the define but comes from another part of the recipe. > > In your solution File[''debugfile''] cannot exist before or you have a > duplicate definition issue. >> When I understand you correctly you want this, as defines implicitly >> "require" all described objects: >> >> define test($testme, $pathvar){ >> file { test: } >> file {''debugfile'': >> path => "$pathvar" >> } >> >> where $pathvar is just introduced to not break the convention to not >> use anything but variables in defines. >> hope i understood your question correctly.. >> >> > > > ------------------------------------------------------------------------ > > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users >
Luke Kanies
2007-Apr-20 14:16 UTC
Re: dependency and communication between defined classes
On Apr 19, 2007, at 2:21 PM, Blake Barnett wrote:>> Maybe I should just add a function like ''nodevar'': >> >> $var = nodevar(variable) >> >> That would correctly look through the tree of node scopes, so that >> nodes could override values set in parent nodes. > > I like this last one.I looked into creating this last night, and it turns out that it''s going to be quite a bit of work because of the order in which statements are interpreted and the fact that nodes evaluate all of the other classes. In particular, look at this configuration: class testing { $val = nodevar("myval") } node basenode { $myval = something include testing } node mynode inherits basenode { $myval = somethingelse } In this case, the basenode gets evaluated before mynode, and part of evaluating the ''basenode'' involves evaluating the ''testing'' class, which means that it''s evaluated before mynode is, which means you don''t get the values you want. I''ve been trying to think of simple ways to resolve this, and I don''t think there are any. I think the only real resolution is to rethink ordering as a whole within the parsing process, and likely introducing the ability to declare that a given class requires another, so that we can always guarantee that the required class is evaluated first and thus its variables are set in time for the second. For now, we''re just going to be stuck with no nodevar. -- The great tragedy of Science - the slaying of a beautiful hypothesis by an ugly fact. --Thomas H. Huxley --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Luke Kanies
2007-Apr-20 14:31 UTC
Re: dependency and communication between defined classes
On Apr 20, 2007, at 2:34 AM, ADNET Ghislain wrote:> > define test($testme){ > file { test: } > require => File[''debug''] > } > > so that the user do not have to know the internal of the class and > put requires on all calls of it as the define take cares of it... > same for before, refresh etc...You can just add the require directly: define test($testme) { file { test: require => File[''debug''] } } But this will make it so that people can''t specify their own ''require'' values. There''s no way around that problem right now. -- Brand''s Asymmetry: The past can only be known, not changed. The future can only be changed, not known. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
ADNET Ghislain
2007-Apr-20 15:17 UTC
Re: dependency and communication between defined classes
> You can just add the require directly: > > define test($testme) { > file { test: require => File[''debug''] } > } >yes but that can work for this exemple but if there is 47 objects in the define it make it quite ugly. Also if i define any variable or any include in the define they get included even as the require is not fullfilled: define test($testme) { include testclass file { test: require => File[''debug''] } } in my exemple the include would not be "included" as the global require would prevent the whole define to run before the require. In your way it would be included and then the define would then trigger the require and be sceduled later (if i am not mistaken). this become ordering mayhem !! ;) -- Cordialement, Ghislain _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
Luke Kanies
2007-Apr-20 15:46 UTC
Re: dependency and communication between defined classes
On Apr 20, 2007, at 10:17 AM, ADNET Ghislain wrote:> yes but that can work for this exemple but if there is 47 objects > in the define it make it quite ugly. Also if i define any variable > or any include in the define they get included even as the require > is not fullfilled: > > define test($testme) { > include testclass > file { test: require => File[''debug''] } > } > > > in my exemple the include would not be "included" as the global > require would prevent the whole define to run before the require. > In your way it would be included and then the define would then > trigger the require and be sceduled later (if i am not mistaken). > > this become ordering mayhem !! ;)Yeah, I think it''s pretty clear that the language needs more ability to specify relationships between groups of resources, but I don''t know when I''ll have time to do that. If this is a big problem for you, I''m available for paid custom development to get it done sooner, but otherwise, I can''t make any promises about when it will end up on my todo list. -- It is a mistake to think you can solve any major problems just with potatoes. --Douglas Adams --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Jeff McCune
2007-Apr-26 14:09 UTC
Re: dependency and communication between defined classes
Luke Kanies wrote:> On Apr 20, 2007, at 2:34 AM, ADNET Ghislain wrote: >> define test($testme){ >> file { test: } >> require => File[''debug''] >> } >> >> so that the user do not have to know the internal of the class and >> put requires on all calls of it as the define take cares of it... >> same for before, refresh etc... > > You can just add the require directly: > > define test($testme) { > file { test: require => File[''debug''] } > } > > But this will make it so that people can''t specify their own > ''require'' values. > > There''s no way around that problem right now.Sorry for jumping in late, catching up on email. Maybe what I think is working isn''t, but I''ve been forcing requires in my defines and allowing callers to define additional requirements by using selectors, defaults, and lists. I believe this works if the caller passes a singleton or a list. Take note of $require_real => $require ? { } # Copy things out of a subversion working copy. define file_from_cache($source = false, $sourcedir = "/Support/vault/cache", $destdir = false, $owner = 0, $group = 0, $mode = 0640, $recurse = true, $ignore = ".svn", $backup = false, $require = false ) { $source_real = $source ? { false => $name, default => $source } $name_real = $destdir ? { false => $name, default => "$destdir/$name" } # Require the subversion working copy. # This is created in the siteconf-tree class, so include it too. $require_real = $require ? { false => Svnworkdir["FileCache"], default => [ Svnworkdir["FileCache"], $require] } # We always need the siteconf-tree when copying files from the cache. # FIXME: Local only mode? include siteconf-tree # The actual file to copy from the svn working copy. file { $name_real: source => "$sourcedir/$source_real", owner => $owner, group => $group, mode => $mode, recurse => $recurse, ignore => $ignore, backup => $backup, require => $require_real } } class siteconf-tree { svnworkdir { "FileCache": repository => "https://manage.lan/svn/siteconfig/trunk", local_name => "cache" } } -- Jeff McCune The Ohio State University Department of Mathematics Systems Manager _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
Luke Kanies
2007-Apr-26 15:54 UTC
Re: dependency and communication between defined classes
On Apr 26, 2007, at 9:09 AM, Jeff McCune wrote:> Sorry for jumping in late, catching up on email. > > Maybe what I think is working isn''t, but I''ve been forcing requires in > my defines and allowing callers to define additional requirements by > using selectors, defaults, and lists. I believe this works if the > caller passes a singleton or a list.I''d be shocked if it worked if you pass in an array: define test() { exec { "/bin/echo testing $name": subscribe => [Exec[one], $subscribe] } } exec { one: command => "/bin/echo one", refreshonly => true } exec { two: command => "/bin/echo two", refreshonly => true } exec { three: command => "/bin/echo three", refreshonly => true } test { yay: subscribe => [Exec[two], Exec[three]] } Produces: err: Could not apply complete configuration: Could not retrieve dependency ''Exec[two][Exec[three]]'' at /Users/luke/bin/test2.pp:4 -- A diplomat is a man who can convince his wife she''d look stout in a fur coat. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Jeff McCune
2007-Apr-26 16:26 UTC
Re: dependency and communication between defined classes
Luke Kanies wrote:> On Apr 26, 2007, at 9:09 AM, Jeff McCune wrote: >> Sorry for jumping in late, catching up on email. >> >> Maybe what I think is working isn''t, but I''ve been forcing requires in >> my defines and allowing callers to define additional requirements by >> using selectors, defaults, and lists. I believe this works if the >> caller passes a singleton or a list. > > I''d be shocked if it worked if you pass in an array: > > define test() { > exec { "/bin/echo testing $name": subscribe => [Exec[one], > $subscribe] } > } > > exec { one: command => "/bin/echo one", refreshonly => true } > exec { two: command => "/bin/echo two", refreshonly => true } > exec { three: command => "/bin/echo three", refreshonly => true } > test { yay: subscribe => [Exec[two], Exec[three]] } > > Produces: > > err: Could not apply complete configuration: Could not retrieve > dependency ''Exec[two][Exec[three]]'' at /Users/luke/bin/test2.pp:4Yep, you''re right. Bummer. -- Jeff McCune The Ohio State University Department of Mathematics Systems Manager _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users