3
votes

I am seeing a weird issue when running my chef cookbook, it almost looks like there is some stale variable names being used in between runs even after modifying the json env file. Please see below for more details. I have pasted excerpts from my template, and environment files. Also showed the desired output and the current weird output that I am seeing. It may be something with my ruby loops (excuse my ruby, noob here) but I have checked it multiple times and don't see any issue with the construct.

Any help appreciated... have been messing with this for almost 24 hours now, in the interest of being productive I am reaching out to others.

This is my first post here and I am not allowed to post more than 2 links in the content. I had to remove the 'http' and 'https' from my sample output and rename my domain names to bypass.

Template:

gatewaymappings: |  
  {  
    <% @gatewaymappings.each_with_index do |mapping, index| %>      
       "<%= mapping.incomingFQDN %>" : "<%= mapping.upstreamProtocol %>://<%= mapping.upstreamFQDN %>  
          <% if (mapping.upstreamPort.length > 0) %>  
            :<%= mapping.upstreamPort %>"  
         <% end %>  
          <% if (index+1 != @gatewaymappings.count) %>  
            ,  
         <% end %>  
   <% end %>  
  }

Chef template variables:
:gatewaymappings => node[app_name]['gatewaymappings']

Sample JSON:

"gatewaymappings": [  
  {  
    "incomingFQDN": "host1",  
    "upstreamProtocol": "http",  
    "upstreamFQDN": "upstream1",  
    "upstreamPort": "8000"  
  },  
  {  
    "incomingFQDN": "host2",  
    "upstreamProtocol": "https",  
    "upstreamFQDN": "upstream2",  
    "upstreamPort": "8001"  
  }  
]  

Desired output: (inside yml file)

 gatewaymappings: |  
  {  
      "host1" : "upstream1:8000",  
      "host2" : "upstream2:8001"  
  }  

Current output:
(The first element is from a previous sample env run which doesnt even exist in my current sample json, I tried clearing cache etc, but it still keep showing up)

gatewaymappings: |  
  {  
      "localhost" : "upstream",  
      "host1" : "upstream1:8000",  
      "host2" : "upstream2:8001",  
      "host1" : "upstream1:8000",  
      "host2" : "upstream2:8001"  
  }  
1
Your post would be more readable if you could use markdown to format code and information. - Marc-Andre
sorry, I will try to format it better. my first post here. thanks. - SKK
No problem, we all need to start somewhere and learn new things! - Marc-Andre

1 Answers

0
votes

I think I was able to fix this. It was due to my node configs being corrupted. I should have mentioned I was using chef-zero. It turns out the node config is saved back to a json file inside nodes directory even for chef-zero and so no matter how many times I deleted my local-mode caches inside ~/.chef and my installation directories, the stale values kept coming back. Thanks to gitter chat room, someone gave me a gentle reminder to check the node's configs. That took care of the issue and I am seeing my expected output now. Thanks!