Update Chef Attributes at Chef-Client run time

382 Views Asked by At

What's up guys, I'm currently trying to update one of my cookbooks attributes at chef-client runtime, inside my recipe. However, I don't think I'm doing this correctly and tbh I don't know if this is even possible. Here's what I'm attempting:

My Attributes/default.rb looks like this:

default['jenkins']['master']['host'] = lazy { node.run_state['jenkinsHost'] } 
default['jenkins']['master']['port'] = 8080 
default['jenkins']['master']['endpoint'] = lazy { "http://#{node['master']['host']}:8080"}

and in my recipe/default.rb I have the following:

aws_ssm_parameter_store 'getJenkinsMasterHost' do
    path '/Global/Jenkins/MasterHost'
    return_keys 'jenkinsHost'
    action :get
end

node.run_state[:jenkins_master_endpoint] = "http://#{node.run_state['jenkinsHost']}:8080"

trying to override the default['jenkins']['master']['endpoint'] attribute with whatever gets pulled down from ssm parameter store.

Please help.

1

There are 1 best solutions below

0
Moises Ayala On

One of my coworkers assisted me with this and recommended I put this in a ruby_block resource, with the following code see below for the snippet:

ruby_block 'update jenkins endpoint' do
  block do
    node.override['jenkins']['master']['endpoint'] = "http://#{node.run_state['jenkinsHost']}:8080"
  end
  action :run 
end