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"
}