using ruby dsl in puppet manifest

703 views
Skip to first unread message

Ritesh Nanda

unread,
May 8, 2014, 5:03:37 PM5/8/14
to puppet...@googlegroups.com
Hello ,

I would like to use ruby dsl in my manifest . Online doc for this topic is very limited , i am stuck at a place where i want to use ruby DIr class to find a particular file in a directory and then run operation on it . 
Is it possible to use  ruby dsl for puppet in this way. 


Regards,
Ritesh Nanda


Henrik Lindberg

unread,
May 8, 2014, 5:16:10 PM5/8/14
to puppet...@googlegroups.com
The ruby DSL is deprecated and will be removed in Puppet 4.

What you want is probably to write a function in Ruby.
The deprecated Ruby DSL was a way to write manifests in .rb files
instead of .pp files.

If what you want to do is something that executes on the master side,
you implement it as a function. If it is something that should run on
the agent, it is implemented as a resource type.

Regards
- henrik

>
> Regards,
> Ritesh Nanda
>
>
> --
> 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
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/fcb75cd4-68fa-4ed6-93a0-596d175f87fe%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/fcb75cd4-68fa-4ed6-93a0-596d175f87fe%40googlegroups..com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


Ritesh Nanda

unread,
May 8, 2014, 5:36:56 PM5/8/14
to puppet...@googlegroups.com
Thanks Henrik ,

I would like to find a file and  parse it  , so that would be on the agent , creating a puppet function would not work , as master  will not be able to access those files.
You said Can be done with Resources , how can i include a ruby block in my manifest , i know using exec resource i can run a ruby script , but any better way to do it.


Regards,
Ritesh




On Thu, May 8, 2014 at 11:16 AM, Henrik Lindberg <henrik....@cloudsmith.com> wrote:
On 2014-08-05 19:03, Ritesh Nanda wrote:
Hello ,

I would like to use ruby dsl in my manifest . Online doc for this topic
is very limited , i am stuck at a place where i want to use ruby DIr
class to find a particular file in a directory and then run operation on
it .
Is it possible to use  ruby dsl for puppet in this way.

The ruby DSL is deprecated and will be removed in Puppet 4.

What you want is probably to write a function in Ruby.
The deprecated Ruby DSL was a way to write manifests in .rb files instead of .pp files.

If what you want to do is something that executes on the master side, you implement it as a function. If it is something that should run on the agent, it is implemented as a resource type.

Regards
- henrik


Regards,
Ritesh Nanda


--
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


--
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/3lD1tChZQJw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/lkge4q%24tb1%241%40ger.gmane.org.

For more options, visit https://groups.google.com/d/optout.



--

 With Regards 

 Ritesh Nanda




Henrik Lindberg

unread,
May 9, 2014, 1:17:40 AM5/9/14
to puppet...@googlegroups.com
On 2014-08-05 19:36, Ritesh Nanda wrote:
> Thanks Henrik ,
>
> I would like to find a file and parse it , so that would be on the
> agent , creating a puppet function would not work , as master will not
> be able to access those files.
> You said Can be done with Resources , how can i include a ruby block in
> my manifest , i know using exec resource i can run a ruby script , but
> any better way to do it.
>
Depends on what you are parsing, and what you need to do with the parsed
result. You may find that there is already a module that does what you want.

Basically, the logic that does that has to be an implementation of a
resource type. That is what is responsible for syncing the state of the
agent where it is running with what is on that agent. It gets what was
specified in the manifests in a resource, and the provider logic for
that resource type then does the sync.

That is how all resource types / providers work.

This may help you:
http://doauto.wordpress.com/2013/06/22/how-to-change-a-file-using-puppet/

And you have Augeas where you can write "lenses" (plugins) to Augeas to
handle specific syntax.

http://docs.puppetlabs.com/guides/augeas.html#loading-generic-lenses-for-non-standard-files

http://bombasticmonkey.com/2011/01/02/distributing-augeas-lenses-with-pluginsync/

Hope that helps.
- henrik


Ritesh Nanda

unread,
May 9, 2014, 4:24:49 PM5/9/14
to puppet...@googlegroups.com
Hello Henrik ,

Thanks for your reply , i was also thinking to create a type and provider using existing parser functionality  puppet has . Even thanks for sharing those links , it was helpful.

Regards,
Ritesh Nanda




--
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/3lD1tChZQJw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

jcbollinger

unread,
May 9, 2014, 5:46:03 PM5/9/14
to puppet...@googlegroups.com


On Thursday, May 8, 2014 12:36:56 PM UTC-5, Ritesh Nanda wrote:
Thanks Henrik ,

I would like to find a file and  parse it  , so that would be on the agent , creating a puppet function would not work , as master  will not be able to access those files.


Neither would anything written in Ruby DSL, for much the same reason.

 
You said Can be done with Resources , how can i include a ruby block in my manifest , i know using exec resource i can run a ruby script , but any better way to do it.



You can execute more or less arbitrary Ruby code from your manifest via an ERB template, using the built-in template() or inline_template() function.  You can serve some purposes for which you might want Ruby by enabling and using the 'future' parser.  But all of that runs on the master, in order to build a "catalog" describing the resources and properties to manage on the target node.

If you want to run custom Ruby code on the client as part of a Puppet run then you must build a plugin with which Puppet (or Facter) will do so.  If the purpose is to gather information to inform catalog construction, then your plugin should be a custom fact.  If the purpose is to modify the system then you want a custom resource type and a provider for it.


John

Ritesh Nanda

unread,
May 11, 2014, 12:49:18 AM5/11/14
to puppet...@googlegroups.com
Hello John,

Thanks for your reply , ruby code i was trying to run was on client , so i am doing with inline_template right now , yeah but your idea seems good to have a plugin to do it .

I would start thinking on it , thanks for your help.

Regards,
Ritesh


--
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/3lD1tChZQJw/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/c92d012d-99c6-4de3-b74e-44beda2e3622%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

jcbollinger

unread,
May 12, 2014, 1:05:41 PM5/12/14
to puppet...@googlegroups.com


On Saturday, May 10, 2014 7:49:18 PM UTC-5, Ritesh Nanda wrote:
Hello John,

Thanks for your reply , ruby code i was trying to run was on client , so i am doing with inline_template right now , yeah but your idea seems good to have a plugin to do it .


A plugin or an Exec is the only place to do it.  As I wrote, templates are evaluated on the master, so inline_template() will not do what you want.  If your code must run on the agent then it must be in a custom fact or in the provider of a custom type, it must be run via an Exec resource.


John

Ritesh Nanda

unread,
May 12, 2014, 4:50:37 PM5/12/14
to puppet...@googlegroups.com
Hello John,

I made a mistake in writing , i am using exec resource to execute that script.

Regards,
Ritesh


--
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/3lD1tChZQJw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages