所以这可能有点令人困惑,但请耐心等待。简而言之,我想遍历具有某个键值的所有属性,然后如果值不为空,则将它们插入到模板中。这是我的代码:
属性:
# === 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'] = ''
模板:
<% node['elasticsearch']['default'].each do |host| -%>
<% if node.elasticsearch.default.host not nil -%>
<%= host %>=<%= node.elasticsearch.default.host %>
<% end %>
输出(希望):
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
我的 ruby 不是最好的,因为我刚刚开始使用所有这些东西,但我找不到这种情况的任何例子。任何帮助都会很棒,谢谢。