On Apr 9, 2013, at 6:06 AM, tio teath <[email protected]> wrote:
>
>
> On Monday, April 8, 2013 8:06:23 AM UTC+3, Luke Kanies wrote:
> On Apr 7, 2013, at 11:59 AM, tio teath <[email protected]> wrote:
>
>> I would like to use Puppet::Type::File as a base type, and add some custom
>> properties to it without modifying original code, i.e. using separate module
>> under puppet Puppet[:libdir]. What is best approach to achieve this?
>
> Hi,
>
> This might be possible, but probably will be more annoying than you want. If
> that's not enough warning, though...
>
> You can *probably* create a new type and set ':parent => :file' in that type.
> There used to be an option to retain most/all of the attributes (I used this
> for 'tidy' before I refactored it a long time ago), but I can't seem to find
> it now. That makes me even less confident that this will work well.
> I found this method inside of 'tidy':
> def mkfile(path)
> # Force deletion, so directories actually get deleted.
> Puppet::Type.type(:file).new :path => path, :backup => self[:backup],
> :ensure => :absent, :force => true
> end
> This would not save me from the implementing of all of the wanted parameters,
> but it'll be much easier now, thanks.
Yeah, this ended up being much easier to maintain, both in terms of
understanding how Tidy worked and also in terms of the backing API that was
only used by Tidy and no other types.
>
> Can you elaborate on what you're trying to do, and why?
> I need agent side template rendering functionality.
> That's because of the template data, which available only on agent and could
> not be exposed to the master via facts due to security reason. Yeah, I know
> that's kind a sucks, but I got this infrastructure as it was, and it's not up
> to me to change it.
> For the moment, I did implement this as a custom type, but with no useful
> file's parameters like "owner", "mode", etc. So I have double resource
> definition in the class:
> $some_file_resource = 'path_to_file.xml'
> file { $some_file_resource:
> owner => someowner,
> group => somegroup,
> mode => 660,
> require => My_custom_type[$some_file_resource],
> }
>
> my_custom_type { $some_file_resource:
> template =>
> 'puppet:///modules/some_file_resource.xml.erb',
> }
>
> And this is ugly. Having a single section would be much more elegant.
How are you filling out the template? That is, I assume the template has
variables that need to be evaluated; where are those being retrieved from?
My recommendation would be to create a type a bit like tidy, which compiles the
template result and then stores it into the filebucket, and then creates a file
resource specifying that template's content as its content. That is, specify
the content of the file as the checksum of the template, and then Puppet will
do all of the comparisons and such, and all you have to worry about is
compiling the template itself.
--
Luke Kanies | http://about.me/lak | http://puppetlabs.com/ | +1-615-594-8199
Join us at PuppetConf 2013, August 22-23 in San Francisco -
http://bit.ly/pupconf13
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.