Providers


#1

Hi,

I have been playing with a logrotate cookbook where I want to generated logrotate.conf delayed due to other cookbooks input. But for some reason I can’t seem to trigger a provider

resources/logrotate.rb
actions :create
default_action :create

def initialize(*args)
super
@action = :create_logrotate_conf
end

providers/logrotate.rb
def whyrun_supported?
true
end

use_inline_resources

def generate_logrotate_conf
t = template “/etc/logrotate.conf” do
source "logrotate.conf.erb"
mode "0644"
end
end

action :create do
Chef::Log.warn "------ never run -----------"
generate_logrotate_conf
end

and in my recipe I have I’m running a definition like so

    logrotate "#{curfile}" do
        enabled node['logrotate']["#{curfile}"]['enabled']
        logs node['logrotate']["#{curfile}"]['logs']
        options node['logrotate']["#{curfile}"]['options']
        ifpostrotate node['logrotate']["#{curfile}"]['ifpostrotate']
        postrotate node['logrotate']["#{curfile}"]['postrotate']
        ifprerotate node['logrotate']["#{curfile}"]['ifprerotate']
        prerotate node['logrotate']["#{curfile}"]['prerotate']
    action :create
    end

Can anyone point me to what I’m doing wrong or if there is a better way to create the logrotate.conf file when all other cookbooks are done using?


Med venlig hilsen/Kind regards

Kim Nielsen


#2

Hi.

In modern Chef, you should be able to get away with this:

The only time you need to call “updated_by_last_action” in a provider is
when you’re using “pure ruby” to modify system state. If you’re just using
embedded Chef resources like that, the update is handled automatically by
the use_inline_resources line.

-s

On Fri, Aug 14, 2015 at 8:58 AM, Kim Nielsen kgn@one.com wrote:

Hi,

I have been playing with a logrotate cookbook where I want to generated
logrotate.conf delayed due to other cookbooks input. But for some reason I
can’t seem to trigger a provider

resources/logrotate.rb
actions :create
default_action :create

def initialize(*args)
super
@action = :create_logrotate_conf
end

providers/logrotate.rb
def whyrun_supported?
true
end

use_inline_resources

def generate_logrotate_conf
t = template “/etc/logrotate.conf” do
source "logrotate.conf.erb"
mode "0644"
end
end

action :create do
Chef::Log.warn "------ never run -----------"
generate_logrotate_conf
end

and in my recipe I have I’m running a definition like so

    logrotate "#{curfile}" do
        enabled node['logrotate']["#{curfile}"]['enabled']
        logs node['logrotate']["#{curfile}"]['logs']
        options node['logrotate']["#{curfile}"]['options']
        ifpostrotate node['logrotate']["#{curfile}"]['ifpostrotate']
        postrotate node['logrotate']["#{curfile}"]['postrotate']
        ifprerotate node['logrotate']["#{curfile}"]['ifprerotate']
        prerotate node['logrotate']["#{curfile}"]['prerotate']
        action :create
    end

Can anyone point me to what I’m doing wrong or if there is a better way to
create the logrotate.conf file when all other cookbooks are done using?


Med venlig hilsen/Kind regards

Kim Nielsen


#3

On 14 Aug 2015, at 16:56, Sean OMeara someara@chef.io wrote:

Hi.

In modern Chef, you should be able to get away with this:

https://gist.github.com/someara/221fcefd7642c47e5032

The only time you need to call “updated_by_last_action” in a provider is when you’re using “pure ruby” to modify system state. If you’re just using embedded Chef resources like that, the update is handled automatically by the use_inline_resources line.

Thanks for the example … I have cut’n’pasted your code but its never triggered :frowning:


Med venlig hilsen/Kind regards

Kim Nielsen