Is it possible to run functions at run time ?

48 views
Skip to first unread message

Yanis Guenane

unread,
Nov 27, 2012, 5:23:50 PM11/27/12
to puppet...@googlegroups.com
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,

Yanis Guenane

unread,
Nov 27, 2012, 5:58:05 PM11/27/12
to puppet...@googlegroups.com
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() {
Message has been deleted

joe

unread,
Nov 27, 2012, 7:19:14 PM11/27/12
to puppet...@googlegroups.com
You should set the path based on the value of $myclass::provider:

if $myclass::provider == 'package' {
  test = '/path/a'
}
else {
  test = '/path/b'

Yanis Guenane

unread,
Nov 28, 2012, 2:54:48 AM11/28/12
to puppet...@googlegroups.com
Thanks, I don't know why I tried to make it hard when it could be simple.

jcbollinger

unread,
Nov 28, 2012, 9:50:01 AM11/28/12
to puppet...@googlegroups.com


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

Yanis Guenane

unread,
Dec 1, 2012, 7:55:11 AM12/1/12
to puppet...@googlegroups.com
Thank you John for the answer, it clarified some doubts I had.
Reply all
Reply to author
Forward
0 new messages