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


Chronological Thread 
  • From: Christian Fröstl < >
  • To: " " < >
  • Subject: [chef] Problems with search Funktion in same recipe during first run
  • Date: Tue, 12 Aug 2014 11:35:37 +0000
  • Accept-language: de-DE, en-US

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.

§