How to I get a chef custom lwrp to implement notif

2019-05-11 21:15发布

I write a custom Lightweight resource. But the notifies and only_if is not recognized.

Anyone else get this working?

I use these in opsworks supplies resources. So I know I am using them correctly. Unfortunately proprietary code, so I can't post the code.

标签: chef lwrp
3条回答
走好不送
2楼-- · 2019-05-11 21:48

Here is an example from Opscode

action :create do
  t = template "/etc/cron.d/#{new_resource.name}" do
    cookbook new_resource.cookbook
    source "cron.d.erb"
    mode "0644"
    variables({
        :name => new_resource.name,
        :minute => new_resource.minute,
        :hour => new_resource.hour,
        :day => new_resource.day,
        :month => new_resource.month,
        :weekday => new_resource.weekday,
        :command => new_resource.command,
        :user => new_resource.user,
        :mailto => new_resource.mailto,
        :path => new_resource.path,
        :home => new_resource.home,
        :shell => new_resource.shell
      })
    action :create
  end
  new_resource.updated_by_last_action(t.updated_by_last_action?)
end

If you want to research more deep just follow the link.

查看更多
\"骚年 ilove
3楼-- · 2019-05-11 21:49

Ok. RTFM. Well not really. I did not find this specific issue covered. If you write your own light weight resource and want to be able to use notifies, then use

  • new_resource.updated_by_last_action(false) or
  • new_resource.updated_by_last_action(true)

    in your resource action code.

notifies will then happen (true) or not happen(false).

查看更多
干净又极端
4楼-- · 2019-05-11 21:57

Seemingly, the solution mentioned by @Robert never worked, as mentioned in Chef issue #3748. A working solution would be to use 'use_inline_resources'.

查看更多
登录 后发表回答