[chef] Re: Problems with search Funktion in same recipe during first run


Chronological Thread 
  • From: Jorge Espada < >
  • To:
  • Subject: [chef] Re: Problems with search Funktion in same recipe during first run
  • Date: Tue, 12 Aug 2014 13:33:12 -0300

I think what you probably need to do is reload  node attributes (after the node.set), cause those wont be available  before node.save happens (at the end of the chef run), check the doc, but something like:
node.from_file( run_context.resolve_attribute('cookbook-name', 'default') )

should work


--
Jorge Espada



On Tue, Aug 12, 2014 at 8:35 AM, Christian Fröstl < " target="_blank"> > wrote:
Hi,

I have a partial search in my tomcat recipe. I use it for finding out the
MySQL Server Backend for the tomcat application server.
At the beginning of my tomcat recipe I get the information for the Mysql
Server:

mysql_master_node = partial_search(:node, "roles:mysql_payment_server AND chef_environment:#{node.chef_environment}",
    :keys => { 'name' => ['name'],
               'ip' => ['ipaddress‘],
               'kernel_version' => ['kernel','version']
                                           }
        )
if mysql_master_node.length == 1
          mysql_master_node.each do |result|
            if result['name'] == node['machinename']
              node.set['tc']['payserver']['database_master'] = 'localhost'
            else
              node.set['tc']['payserver']['database_master'] =
mysql_master_node[0]['ip']
            end
          End

During the rest of the recipe, I will use the node variable
node['tc']['payserver'][‚database_master‘] to define the mysql backend
server in the server.xml of the tomcat.

template node['tc']['server_conf_file'] do
  source 'server.xml.erb'
  mode '0644'
  owner 'tomcatusr1'
  group 'tomcatusr1'
  variables({
                :mysql_master    =>
node['tc']['payserver']['database_master'],
            })
  notifies :restart, "service[#{node['tc']['service_name']}]"
End

It seems that the variable will set during the first run, and can only
used in the second chef-client run.
In the first run, the server.xml don’t have the content of
node['tc']['payserver'][‚database_master‘] in it. After the second run,
the file is correct.

Do you have any idea to solve this or is there a better way getting
backend server information?

Thanks in advance,
Christian





Archive powered by MHonArc 2.6.16.

§