title: Chef Ruby loop over attributes in an .erb template file
body: <p>So this might be a little confusing but bear with me.  In short I want to loop over all attributes with a certain key value and then insert them into a template if the values are not empty.  Here is my code:</p>
  
  <p>ATTRIBUTES:</p>
  
  <pre><code># === Default file Configurations
  #
  default['elasticsearch']['default']['ES_USER']              = ''
  default['elasticsearch']['default']['ES_GROUP']             = ''
  default['elasticsearch']['default']['ES_HEAP_SIZE']         = ''
  default['elasticsearch']['default']['MAX_OPEN_FILES']       = ''
  default['elasticsearch']['default']['MAX_LOCKED_MEMORY']    = 'unlimited'
  default['elasticsearch']['default']['MAX_MAP_COUNT']        = ''
  default['elasticsearch']['default']['LOG_DIR']              = '/var/log/elasticsearch'
  default['elasticsearch']['default']['DATA_DIR']             = '/var/lib/elasticsearch'
  default['elasticsearch']['default']['WORK_DIR']             = '/tmp/elasticsearch'
  default['elasticsearch']['default']['CONF_DIR']             = '/etc/elasticsearch'
  default['elasticsearch']['default']['CONF_FILE']            = '/etc/elasticsearch/elasticsearch.yml'
  default['elasticsearch']['default']['RESTART_ON_UPGRADE']   = ''
  </code></pre>
  
  <p>TEMPLATE:</p>
  
  <pre><code>&lt;% node['elasticsearch']['default'].each do |host| -%&gt;
      &lt;% if node.elasticsearch.default.host not nil -%&gt;
          &lt;%= host %&gt;=&lt;%= node.elasticsearch.default.host %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>OUTPUT (hopefully):</p>
  
  <pre><code>MAX_LOCKED_MEMORY=unlimited
  LOG_DIR=/var/log/elasticsearch
  DATA_DIR=/var/lib/elasticsearch
  WORK_DIR=/tmp/elasticsearch
  CONF_DIR=/etc/elasticsearch
  CONF_FILE=/etc/elasticsearch/elasticsearch.yml
  </code></pre>
  
  <p>My ruby isn't the best because I'm just starting out with all of this stuff but I couldn't find any examples for this type of situation.  Any help would be great, thanks.</p>