Calling a puppet function inside a ruby task

45 views
Skip to first unread message

Raghu Ram Baisani

unread,
Feb 4, 2021, 1:53:46 AM2/4/21
to Puppet Users
Hi

Suppose if we have a module named temp,

and we have a puppet function named func1
which resides in temp\lib\puppet\functions\temp\func1.rb

and I have another ruby task in the same module,

temp\tasks\task1.rb

How can I call puppet function func1 on task task1?

Any kind help is appreciated

Cheers
Raghuram Baisani

KevinR

unread,
Feb 4, 2021, 6:42:23 AM2/4/21
to Puppet Users
Hi Raghuram,

this cannot be (easily) achieved from a Task, as the Task execution environment is not Puppet but basically the target's shell.
You can do this from a Bolt Plan however:
  1. In your Bolt module (where your task lives), create a functions folder at the root
  2. Place your function in that folder, i.e.f /functions/func1.rb
  3. Namespace the function according to your module name, for example mymodule::func1
  4. You can now use the module in a Bolt Plan (under /plans) with mymodule::func1(args)
- KevinR

Raghu Ram Baisani

unread,
Feb 4, 2021, 6:45:52 AM2/4/21
to puppet...@googlegroups.com
Thanks Kevin

I'm kind of aware of plan option.

Can you please detail the option for task with an example so that I can know how it works.

Cheers
Raghuram Baisani

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/c6d2d365-3cc8-4513-b4c3-bb0f062d56d5n%40googlegroups.com.

Kevin Reeuwijk

unread,
Feb 4, 2021, 7:25:17 AM2/4/21
to puppet...@googlegroups.com
Hi Raghuram,

The short of it is that you can't make that work in a Task, the Bolt Task environment is simply not designed for this. You have to use a plan.
You can have the Plan call the function and pass the results as parameters to your Task though:

plan mymodule::test {
$func_result = mymodule::func1('arg1', 'arg2')
# assuming mymodule::func1() returns a simple string

run_task('mymodule::mytask', 'target.company.com', 'myparam' => $func_result)
}

-KevinR


You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/psFXomJq4tY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAFfXrBxmXFxLMkZUaGr1bOaMbOjLaS4TNwZdzrAQPqpnmvoJDg%40mail.gmail.com.

Raghu Ram Baisani

unread,
Feb 4, 2021, 8:38:42 AM2/4/21
to puppet...@googlegroups.com
Oh I see thanks for the clarification
Cheers
Raghuram Baisani

Reply all
Reply to author
Forward
0 new messages