Created
March 26, 2013 21:39
-
-
Save behemphi/5249555 to your computer and use it in GitHub Desktop.
A question of execution order:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| In the attributes file, the value is set: | |
| default['feedmagnet']['db']['host_ip'] = 'localhost' | |
| ```ruby | |
| if node.chef_environment.include?('large') | |
| nodes = search(:node, "name:#{node.feedmagnet.instance_name}*") # Three nodes are found (merry-util, merry-console, merry-db) | |
| log "# nodes #{nodes.count()}" # 3 | |
| # Looking for the database host | |
| nodes.each do |node| | |
| log "nodename = #{node}" | |
| # If the database host exists, get its servicenet IP, otherwise fail | |
| # the run. | |
| if node.hostname.index('-db') | |
| node.override['feedmagnet']['db']['host_ip'] = node.cloud.private_ips[0] | |
| log "db servicenet ip = #{node.feedmagnet.db.host_ip}" | |
| end | |
| end | |
| end | |
| log "db servicenet ip before leaving = #{node.feedmagnet.db.host_ip}" # localhost (wtf!) | |
| ``` | |
| So when this runs, I can see the log statement on line 18 spit out the local ip address of merry-db but the log statement on | |
| line 24 says it is still "localhost" as set in the attribute file. | |
| I _thought_ it was my ruby. So I jumped into IRB and abstracted it, and could find nothing wrong. So I hacked out the | |
| assignment on line 17 and moved it out of the loop. (even though I _know_ the value is not getting overwritten there from | |
| the logging statements. | |
| Here is the hacked code: | |
| ```ruby | |
| # If this is a large instance we need to locate the database host. | |
| db_host_ip = '127.0.0.1' | |
| if node.chef_environment.include?('large') | |
| nodes = search(:node, "name:#{node.feedmagnet.instance_name}*") | |
| log "# nodes #{nodes.count()}" | |
| # Looking for the database host | |
| nodes.each do |node| | |
| log "nodename = #{node}" | |
| # If the database host exists, get its servicenet IP, otherwise fail | |
| # the run. | |
| if node.hostname.index('-db') | |
| db_host_ip = node.cloud.private_ips[0] | |
| # log "db servicenet ip = #{node.feedmagnet.db.host_ip}" | |
| end | |
| end | |
| end | |
| node.set['feedmagnet']['db']['host_ip'] = db_host_ip | |
| log "wtf = #{db_host_ip}" | |
| log "db servicenet ip before leaving = #{node.feedmagnet.db.host_ip}" | |
| ``` | |
| Now the attribute value is set correctly!!! That is to say that line 59 returns the value of the local ip of merry-db. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment