Yanis Guenane
2012-Nov-27 22:23 UTC
[Puppet Users] Is it possible to run functions at run time ?
Hi all, I have a manifest that look like this case $provider { ''package'' : { package {''mypackage'' : ensure => latest, } } ''source'' : { exec {''install procedure'' : } } $test = get_test_path() file {''myconf'' : content => templates(''mod/myconf''), } Within mycon template I have a variable ''test'' that depending if the package was installed from source of from the package will have a different path. Issue is that the function get_test_path() seems to be done at compile time, so the first time I run it will always result in an erroneous answer. After a second run it will be fine. Does any one can provide guidance on how I could make it work at the first run ? Thank you, -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/t-tAovcULSoJ. 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.
Yanis Guenane
2012-Nov-27 22:58 UTC
[Puppet Users] Re: Is it possible to run functions at run time ?
*Specification* : my manifest look more like this class myclass ($provider = ''package'') { case $provider { ''package'' : { package {''mypackage'' : ensure => latest, } } ''source'' : { exec {''install procedure'' : } } } define myclass::mydefine() { $test = get_test_path() file {''myconf'' : content => templates(''mod/myconf''), } } On Tuesday, November 27, 2012 11:23:50 PM UTC+1, Yanis Guenane wrote:> > Hi all, > > I have a manifest that look like this > > case $provider { > ''package'' : { > package {''mypackage'' : > ensure => latest, > } > } > ''source'' : { > exec {''install procedure'' : > } > } > > $test = get_test_path() > > file {''myconf'' : > content => templates(''mod/myconf''), > } > > Within mycon template I have a variable ''test'' that depending if the > package was installed from source of from the package will have a different > path. > Issue is that the function get_test_path() seems to be done at compile > time, so the first time I run it will always result in an erroneous answer. > After a second run it will be fine. > > Does any one can provide guidance on how I could make it work at the first > run ? > > Thank you, >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/IvLocvAcfkAJ. 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.
joe
2012-Nov-28 00:17 UTC
[Puppet Users] Re: Is it possible to run functions at run time ?
What you should do instead is set the path based on the value of $myclass::provider. if $myclass::provider == ''package'' { On Tuesday, November 27, 2012 3:58:05 PM UTC-7, Yanis Guenane wrote:> > *Specification* : my manifest look more like this > > class myclass ($provider = ''package'') { > case $provider { > ''package'' : { > package {''mypackage'' : > ensure => latest, > } > } > ''source'' : { > exec {''install procedure'' : > } > } > } > > define myclass::mydefine() { > $test = get_test_path() > > file {''myconf'' : > content => templates(''mod/myconf''), > } > } > > > On Tuesday, November 27, 2012 11:23:50 PM UTC+1, Yanis Guenane wrote: >> >> Hi all, >> >> I have a manifest that look like this >> >> case $provider { >> ''package'' : { >> package {''mypackage'' : >> ensure => latest, >> } >> } >> ''source'' : { >> exec {''install procedure'' : >> } >> } >> >> $test = get_test_path() >> >> file {''myconf'' : >> content => templates(''mod/myconf''), >> } >> >> Within mycon template I have a variable ''test'' that depending if the >> package was installed from source of from the package will have a different >> path. >> Issue is that the function get_test_path() seems to be done at compile >> time, so the first time I run it will always result in an erroneous answer. >> After a second run it will be fine. >> >> Does any one can provide guidance on how I could make it work at the >> first run ? >> >> Thank you, >> >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/ne0VVEvq-VMJ. 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.
joe
2012-Nov-28 00:19 UTC
[Puppet Users] Re: Is it possible to run functions at run time ?
You should set the path based on the value of $myclass::provider: if $myclass::provider == ''package'' { test = ''/path/a'' } else { test = ''/path/b'' } On Tuesday, November 27, 2012 3:58:05 PM UTC-7, Yanis Guenane wrote:> > *Specification* : my manifest look more like this > > class myclass ($provider = ''package'') { > case $provider { > ''package'' : { > package {''mypackage'' : > ensure => latest, > } > } > ''source'' : { > exec {''install procedure'' : > } > } > } > > define myclass::mydefine() { > $test = get_test_path() > > file {''myconf'' : > content => templates(''mod/myconf''), > } > } > > > On Tuesday, November 27, 2012 11:23:50 PM UTC+1, Yanis Guenane wrote: >> >> Hi all, >> >> I have a manifest that look like this >> >> case $provider { >> ''package'' : { >> package {''mypackage'' : >> ensure => latest, >> } >> } >> ''source'' : { >> exec {''install procedure'' : >> } >> } >> >> $test = get_test_path() >> >> file {''myconf'' : >> content => templates(''mod/myconf''), >> } >> >> Within mycon template I have a variable ''test'' that depending if the >> package was installed from source of from the package will have a different >> path. >> Issue is that the function get_test_path() seems to be done at compile >> time, so the first time I run it will always result in an erroneous answer. >> After a second run it will be fine. >> >> Does any one can provide guidance on how I could make it work at the >> first run ? >> >> Thank you, >> >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/hMQYjwpofeIJ. 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.
Yanis Guenane
2012-Nov-28 07:54 UTC
[Puppet Users] Re: Is it possible to run functions at run time ?
Thanks, I don''t know why I tried to make it hard when it could be simple. On Wednesday, November 28, 2012 1:19:14 AM UTC+1, joe wrote:> > You should set the path based on the value of $myclass::provider: > > if $myclass::provider == ''package'' { > test = ''/path/a'' > } > else { > test = ''/path/b'' > } > > On Tuesday, November 27, 2012 3:58:05 PM UTC-7, Yanis Guenane wrote: >> >> *Specification* : my manifest look more like this >> >> class myclass ($provider = ''package'') { >> case $provider { >> ''package'' : { >> package {''mypackage'' : >> ensure => latest, >> } >> } >> ''source'' : { >> exec {''install procedure'' : >> } >> } >> } >> >> define myclass::mydefine() { >> $test = get_test_path() >> >> file {''myconf'' : >> content => templates(''mod/myconf''), >> } >> } >> >> >> On Tuesday, November 27, 2012 11:23:50 PM UTC+1, Yanis Guenane wrote: >>> >>> Hi all, >>> >>> I have a manifest that look like this >>> >>> case $provider { >>> ''package'' : { >>> package {''mypackage'' : >>> ensure => latest, >>> } >>> } >>> ''source'' : { >>> exec {''install procedure'' : >>> } >>> } >>> >>> $test = get_test_path() >>> >>> file {''myconf'' : >>> content => templates(''mod/myconf''), >>> } >>> >>> Within mycon template I have a variable ''test'' that depending if the >>> package was installed from source of from the package will have a different >>> path. >>> Issue is that the function get_test_path() seems to be done at compile >>> time, so the first time I run it will always result in an erroneous answer. >>> After a second run it will be fine. >>> >>> Does any one can provide guidance on how I could make it work at the >>> first run ? >>> >>> Thank you, >>> >>-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/2GJ3Q90QfKAJ. 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.
jcbollinger
2012-Nov-28 14:50 UTC
[Puppet Users] Re: Is it possible to run functions at run time ?
On Tuesday, November 27, 2012 4:23:50 PM UTC-6, Yanis Guenane wrote:> > Within mycon template I have a variable ''test'' that depending if the > package was installed from source of from the package will have a different > path. > Issue is that the function get_test_path() seems to be done at compile > time, so the first time I run it will always result in an erroneous answer. > After a second run it will be fine. > >To answer the question posed by the thread subject, no, it is not possible to make puppet functions be evaluated by the puppet agent during catalog application. They are always evaluated by the master during catalog compilation. Any dynamic behavior you want to happen on the agent side must be performed by your resources. Often you don''t actually need agent-side dynamism beyond what Puppet already provides, but when you do, you generally need either to use an Exec resource, or to write a custom provider for an existing resource type, or to write a whole custom type / provider pair. John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/7FI9BFD4LB0J. 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.
Yanis Guenane
2012-Dec-01 12:55 UTC
[Puppet Users] Re: Is it possible to run functions at run time ?
Thank you John for the answer, it clarified some doubts I had. On Wednesday, November 28, 2012 3:50:01 PM UTC+1, jcbollinger wrote:> > > > On Tuesday, November 27, 2012 4:23:50 PM UTC-6, Yanis Guenane wrote: >> >> Within mycon template I have a variable ''test'' that depending if the >> package was installed from source of from the package will have a different >> path. >> Issue is that the function get_test_path() seems to be done at compile >> time, so the first time I run it will always result in an erroneous answer. >> After a second run it will be fine. >> >> > To answer the question posed by the thread subject, no, it is not possible > to make puppet functions be evaluated by the puppet agent during catalog > application. They are always evaluated by the master during catalog > compilation. > > Any dynamic behavior you want to happen on the agent side must be > performed by your resources. Often you don''t actually need agent-side > dynamism beyond what Puppet already provides, but when you do, you > generally need either to use an Exec resource, or to write a custom > provider for an existing resource type, or to write a whole custom type / > provider pair. > > > John > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/KdHb0O_4OhgJ. 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.