tung dang
2008-Aug-14 04:00 UTC
[Puppet Users] Return value from resource, is it possible ?
Hi friend, As i known, resources don''t have the return value. Do I have other method to return a value after executing a resource? More detail: from client, I want to check 2 connection, if a connection is alive, my own resource will return this value or set a variable with that value, so other resource can use it How can i do like that? Thank for your help TungDH --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Adam Jacob
2008-Aug-14 16:47 UTC
[Puppet Users] Re: Return value from resource, is it possible ?
On Wed, Aug 13, 2008 at 9:00 PM, tung dang <danghuutung@gmail.com> wrote:> Hi friend, > As i known, resources don''t have the return value. Do I have other method to > return a value after executing a resource? More detail: from client, I want > to check 2 connection, if a connection is alive, my own resource will return > this value or set a variable with that value, so other resource can use it > How can i do like that?You can''t really do that in the way you want. If what you are trying to do is take an action depending on whether or not a connection is up, you might do something like: exec { "take-action": command => "do something", refreshonly => true } exec { "connection-is-up": command => "some command", notify => Exec["take-action"] } That will cause the action to be taken only if the connection is up exec returns 0. The reason this won''t work the way you intend is that the manifest is compiled on the server, not the client. This means that by the time you are evaluating the state of your resources, it''s too late to be passing around return codes and altering the execution path. Regards, Adam -- HJK Solutions - We Launch Startups - http://www.hjksolutions.com Adam Jacob, Senior Partner T: (206) 508-4759 E: adam@hjksolutions.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Phillip Scholz
2008-Aug-14 17:01 UTC
[Puppet Users] Re: Return value from resource, is it possible ?
whats wrong with "onlyif" ? exec { "take-action": command => "do something", onlyif => "some command", } Adam Jacob schrieb:> On Wed, Aug 13, 2008 at 9:00 PM, tung dang <danghuutung@gmail.com> wrote: >> Hi friend, >> As i known, resources don''t have the return value. Do I have other method to >> return a value after executing a resource? More detail: from client, I want >> to check 2 connection, if a connection is alive, my own resource will return >> this value or set a variable with that value, so other resource can use it >> How can i do like that? > > You can''t really do that in the way you want. > > If what you are trying to do is take an action depending on whether or > not a connection is up, you might do something like: > > exec { "take-action": > command => "do something", > refreshonly => true > } > > exec { "connection-is-up": > command => "some command", > notify => Exec["take-action"] > } > > That will cause the action to be taken only if the connection is up > exec returns 0. > > The reason this won''t work the way you intend is that the manifest is > compiled on the server, not the client. This means that by the time > you are evaluating the state of your resources, it''s too late to be > passing around return codes and altering the execution path. > > Regards, > Adam >--
Adam Jacob
2008-Aug-14 17:03 UTC
[Puppet Users] Re: Return value from resource, is it possible ?
Nothing at all! Clearly written pre-coffee. :) Adam On Thu, Aug 14, 2008 at 10:01 AM, Phillip Scholz <phillip.scholz@1und1.de> wrote:> whats wrong with "onlyif" ? > > exec { "take-action": > command => "do something", > onlyif => "some command", > } > > > > Adam Jacob schrieb: >> >> On Wed, Aug 13, 2008 at 9:00 PM, tung dang <danghuutung@gmail.com> wrote: >>> >>> Hi friend, >>> As i known, resources don''t have the return value. Do I have other method >>> to >>> return a value after executing a resource? More detail: from client, I >>> want >>> to check 2 connection, if a connection is alive, my own resource will >>> return >>> this value or set a variable with that value, so other resource can use >>> it >>> How can i do like that? >> >> You can''t really do that in the way you want. >> >> If what you are trying to do is take an action depending on whether or >> not a connection is up, you might do something like: >> >> exec { "take-action": >> command => "do something", >> refreshonly => true >> } >> >> exec { "connection-is-up": >> command => "some command", >> notify => Exec["take-action"] >> } >> >> That will cause the action to be taken only if the connection is up >> exec returns 0. >> >> The reason this won''t work the way you intend is that the manifest is >> compiled on the server, not the client. This means that by the time >> you are evaluating the state of your resources, it''s too late to be >> passing around return codes and altering the execution path. >> >> Regards, >> Adam >> > > -- > >-- HJK Solutions - We Launch Startups - http://www.hjksolutions.com Adam Jacob, Senior Partner T: (206) 508-4759 E: adam@hjksolutions.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
tung dang
2008-Aug-15 03:00 UTC
[Puppet Users] Re: Return value from resource, is it possible ?
Thank you very much Your answer help me solve many questions. My solution is checking connection on the server (I wrote a function in Ruby to check connections, and return the successful connection). But sometime, this solution is not very good, because the connection can be success with server, but also can be failure with client (it depends on configuration, firewall, etc ..) Although, thank you very much for your help TungDH> The reason this won''t work the way you intend is that the manifest is > compiled on the server, not the client. This means that by the time > you are evaluating the state of your resources, it''s too late to be > passing around return codes and altering the execution path. > > Regards, > Adam > > -- > HJK Solutions - We Launch Startups - http://www.hjksolutions.com > Adam Jacob, Senior Partner > T: (206) 508-4759 E: adam@hjksolutions.com > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---