using commands with generated path

34 views
Skip to first unread message

Corey Osman

unread,
Dec 11, 2015, 12:08:08 PM12/11/15
to Puppet Dev
Hi,

I am curious on a few things

1. Is the custom type code run on the node or master, makes sense the provider is but not sure about the type code.

2. How would I use the commands syntax with a command path determined by parsing and XML file.  Or passed via the user.

Basically I was hoping to do something like this:



Corey

John Bollinger

unread,
Dec 11, 2015, 1:49:40 PM12/11/15
to Puppet Developers


On Friday, December 11, 2015 at 11:08:08 AM UTC-6, Corey Osman wrote:
Hi,

I am curious on a few things

1. Is the custom type code run on the node or master, makes sense the provider is but not sure about the type code.


As I understand it, a custom type's own code -- or at least parts of it -- runs both in the agent and in the master.  To the best of my knowledge, providers run only in the agent.

 

2. How would I use the commands syntax with a command path determined by parsing and XML file.  Or passed via the user.



I don't think you can do.  Maybe the XML file would work, if you are willing to assume that its contents to be in place and correct before the first Puppet run, and to not thereafter change, but those are pretty strong conditions.  I don't see how the user could provide the information via a Puppet manifest, because it applies to the whole class, whereas user data is specific to individual instances, and user data anywat comes into play only after the suitability-determination aspects the declared commands comes into play.

 
I am uncertain where variable 'imcl_command_path' variable is coming from in provider you point to, and uncertain whether that provider actually works as intended.  If it does work reliably, then I presume the constraints I gave earlier are satisfied (the data source is pre-established, reliably correct, and unchanging for the duration of the Puppet process in which the associated variable is used).


John

Corey Osman

unread,
Dec 11, 2015, 4:09:49 PM12/11/15
to Puppet Developers


On Friday, December 11, 2015 at 10:49:40 AM UTC-8, John Bollinger wrote:


On Friday, December 11, 2015 at 11:08:08 AM UTC-6, Corey Osman wrote:
Hi,

I am curious on a few things

1. Is the custom type code run on the node or master, makes sense the provider is but not sure about the type code.


As I understand it, a custom type's own code -- or at least parts of it -- runs both in the agent and in the master.  To the best of my knowledge, providers run only in the agent.

 
So if I wanted to run some validation in the type code, where does that get run?  node or master?  The reason why I am asking because not only do I want to validate that the user specified a absolute path, but also verify the file exists.  But this would only work if the File.exists? method in the validate block for the type code is executed on the node.

John Bollinger

unread,
Dec 14, 2015, 10:12:28 AM12/14/15
to Puppet Developers


On Friday, December 11, 2015 at 3:09:49 PM UTC-6, Corey Osman wrote:


On Friday, December 11, 2015 at 10:49:40 AM UTC-8, John Bollinger wrote:


On Friday, December 11, 2015 at 11:08:08 AM UTC-6, Corey Osman wrote:
Hi,

I am curious on a few things

1. Is the custom type code run on the node or master, makes sense the provider is but not sure about the type code.


As I understand it, a custom type's own code -- or at least parts of it -- runs both in the agent and in the master.  To the best of my knowledge, providers run only in the agent.

 
So if I wanted to run some validation in the type code, where does that get run?  node or master?


Validation and munging hooks for property and parameter values definitely run on the master.  If you try to specify an invalid value then catalog building will fail.  I don't recall whether they run again on the node.

 
 The reason why I am asking because not only do I want to validate that the user specified a absolute path, but also verify the file exists.  But this would only work if the File.exists? method in the validate block for the type code is executed on the node.


This is not a job for a validation hook, but your provider can perform such a test at whatever point is appropriate, and fail the resource if need be.  Since it is conceivable that the file of interest might itself be managed by Puppet, this also seems like a textbook case for an autorequire -- that would appear in the type, not the provider.


John

Felix Frank

unread,
Dec 14, 2015, 11:29:23 AM12/14/15
to puppe...@googlegroups.com
Hi,

On 12/14/2015 04:12 PM, John Bollinger wrote:
> So if I wanted to run some validation in the type code, where does
> that get run? node or master?
>
>
>
> Validation and munging hooks for property and parameter values
> definitely run on the master. If you try to specify an invalid value
> then catalog building will fail. I don't recall whether they run again
> on the node.

Nope. All the compiler does is make sure that all attributes you specify
are available for the resource type in question.

All hooks are invoked by the agent. Yes, the whole catalog will fail
before any resource is checked or synced, but that's because validation
etc. is run at the very start of the agent transaction.

> The reason why I am asking because not only do I want to validate
> that the user specified a absolute path, but also verify the file
> exists. But this would only work if the File.exists? method in the
> validate block for the type code is executed on the node.
>
>
>
> This is not a job for a validation hook, but your provider can perform
> such a test at whatever point is appropriate, and fail the resource if
> need be. Since it is conceivable that the file of interest might itself
> be managed by Puppet, this also seems like a textbook case for an
> autorequire
> <https://docs.puppetlabs.com/guides/custom_types.html#automatic-relationships>
> -- /that/ would appear in the type, not the provider.

Agreed! Validation should be a function that yields the same result for
the same input in any circumstance.

Cheers,
Felix

John Bollinger

unread,
Dec 15, 2015, 9:06:41 AM12/15/15
to Puppet Developers


On Monday, December 14, 2015 at 10:29:23 AM UTC-6, Felix Frank wrote:
Hi,

On 12/14/2015 04:12 PM, John Bollinger wrote:
[...]


Nope. All the compiler does is make sure that all attributes you specify
are available for the resource type in question.

All hooks are invoked by the agent.


Well, oops.  Thanks for the correction.  Does anyone have a spare can of egg remover?
 

John

Trevor Vaughan

unread,
Dec 28, 2015, 11:12:38 AM12/28/15
to puppe...@googlegroups.com
Actually, I'm 90% sure that John is correct in that the munging and validation hooks run on the server.

Corey, you can snag the learning type/provider that I pushed into the forge and it should print everything to the logs appropriately.

https://forge.puppetlabs.com/onyxpoint/learning_custom_types

I haven't tested it in Puppet 4 yet, but it should work.

Thanks,

Trevor


--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/566EEE5F.8040009%40alumni.tu-berlin.de.
For more options, visit https://groups.google.com/d/optout.



--
Trevor Vaughan
Vice President, Onyx Point, Inc
(410) 541-6699

-- This account not approved for unencrypted proprietary information --
Reply all
Reply to author
Forward
0 new messages