如何在厨师食谱中记录node.run_state的值?

时间:2018-09-01 08:36:02

标签: ruby chef chef-recipe

我有如下食谱

target = node['zookeeper']['override']['target']
remote_file target do
    source node['zookeeper']['override']['url']
    owner   'root'
    group   'root'
    mode    '0644'
    action  :create_if_missing
end

ruby_block 'check_zookeeper_upgraded' do
    block do
        node.run_state['zookeeper_upgraded'] = File.readlink('/usr/lib/zookeeper/zookeeper.jar').equal?(target)
    end
end

link '/usr/lib/zookeeper/zookeeper.jar' do
    group 'root'
    owner 'root'
    to target
    action :create
    not_if { node.run_state['zookeeper_upgraded'] }
end

file '/usr/lib/zookeeper/zookeeper-3.4.8.jar' do
    action :delete
    only_if { ::File.exist? '/usr/lib/zookeeper/zookeeper-3.4.8.jar' }
end

file '/usr/lib/zookeeper/zookeeper-3.4.5-cdh5.15.0.jar' do
    action :delete
    only_if { ::File.exist? '/usr/lib/zookeeper/zookeeper-3.4.5-cdh5.15.0.jar' }
end

service 'zookeeper-server' do
    provider Chef::Provider::Service::Upstart
    action :restart
    ignore_failure true
    only_if { !node.run_state['zookeeper_upgraded'] && !::File.exist?('/etc/init/zookeeper-server.override')}
end

有人可以让我知道如何记录node.run_state['zookeeper_upgraded']的值,以便我可以检查zookeeper-server是否最终重新启动吗?

0 个答案:

没有答案