有没有办法遍历 node.run_state 数据?这是在具有 Active Directory 用户的 RHEL 环境中。我有一个填充 node.run_state 的红宝石块。我必须在收敛时间运行这个,因为整个食谱将用于构建自动化。在第一次运行时,cookbook 会安装 Centrify,然后需要运行 adquery 来收集用户信息,以便使用 SSH 密钥填充主目录。
在厨师客户端运行时,我看到了这个:
Compiling Cookbooks...
{}
显然,这是针对空哈希在编译时运行的 put。在收敛时间,2 目录和 1 模板资源的循环中没有任何反应。
这是食谱的相关部分:
ruby_block 'set uid, gid, and homedir for users' do
block do
base_attr['ssh_keys'].each do |user, pubkeys|
# next unless Dir.exist?(homedir)
node.run_state[user] = {}
puts "Checking user #{user}..."
if local_users.key?(user)
node.run_state[user]['homedir'] = local_users[user]['homedir']
node.run_state[user]['uid'] = local_users[user]['uid'].to_i
node.run_state[user]['gid'] = local_users[user]['gid'].to_i
elsif centrify_users.key?(user)
node.run_state[user]['homedir'] = centrify_users[user]['homedir']
node.run_state[user]['uid'] = centrify_users[user]['uid'].to_i
node.run_state[user]['gid'] = centrify_users[user]['gid'].to_i
else
puts "user #{user} not found."
# Place holder values.
node.run_state[user]['homedir'] = "/tmp/#{user}"
node.run_state[user]['uid'] = 0
node.run_state[user]['gid'] = 0
end
end
end
end
# Dir.exist? guard should bypass compile-time error.
# "name is a required property"
# next unless Dir.exist?(homedir)
puts node.run_state
node.run_state.each do |user|
directory node.run_state[user]['homedir'] do
owner node.run_state[user]['uid']
group node.run_state[user]['gid']
mode '0700'
end
directory "#{node.run_state[user]['homedir']}/.ssh" do
owner node.run_state[user]['uid']
group node.run_state[user]['gid']
mode '0700'
end
template "#{node.run_state[user]['homedir']}/.ssh/authorized_keys" do
owner node.run_state[user]['uid']
group node.run_state[user]['gid']
mode '0600'
source 'authorized_keys.erb'
variables(
sshkeys: base_attr['ssh_keys'][user]
)
end
end
任何想法如何使这项工作?