访问红宝石块内的厨师资源 [英] Access chef resources inside ruby block

查看:61
本文介绍了访问红宝石块内的厨师资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试通过厨师文档和Google来找到答案,但是我仍然无法提出任何答案。我还不是一个红宝石专家,所以答案可能出在我解决厨师足够的红宝石这个问题上。这是我想要做的:在我的 deploy 资源中,在 before_migrate 属性中,我想在我目前的食谱。我目前正在做的只是将资源填充到块本身中,但是我知道必须有更好的方法。

I've been trying to find the answer to this in the chef docs and through Google, but I've not been able to come up with anything. I'm not a ruby guy (yet), so the answer to this might stem from my approaching the problem with "just enough ruby for Chef". Here's what I want to do: in my deploy resource, in the before_migrate attribute, I want to execute a resource in my current recipe. What I am doing currently is to just stuff the resource into the block itself, but I know there must be a better way to do it.

before_migrate do

    template "#{app_root}/#{applet_name}/local_settings.py" do
        source "local_settings.py.erb"
        owner app_config['user']
        group app_config['group']
        variables(
            :database_name => app_config['postgresql']['database_name'],
            :user => app_config['postgresql']['user'],
            :password => app_config['postgresql']['password']
        )   
        action :create
    end 
end 

我的目标是类似

before_migrate do
    "template #{app_root}/#{applet_name}/local_settings.py".execute
end

所以我可以重复使用该模板代码。谢谢!

So I can re-use that template code. Thanks!

推荐答案

感谢#chef IRC频道中的出色人士,我解决了我的问题。通知资源需要直接使用

Thanks to the great guys in the #chef IRC channel, I solved my problem. The notification resource needs to be accessed directly, using

Chef :: Resource :: Notification.new( template [#{app_root} /# {applet_name} /local_settings.py,:create)

这将通知模板资源来运行:create 操作。

Which will notify the template resource to run the :create action.

这篇关于访问红宝石块内的厨师资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆