I am trying to call the data_bag_item method within an erb template. My sudo users may have multiple sudo cmds so i have embedded them directly into the user's databag like sofile: users/oper.json{"id": "oper","groups": "oper","uid": 977,"shell": "\/bin\/bash","password": "$1$WV1cZLkt$FmFEuRFCGKWaabud6.Gld1","sudo_cmds": [ "ALL=(ALL) NOPASSWD:/sbin/reboot","ALL=(ALL) NOPASSWD:/sbin/poweroff" ]}file: recipes/default.rbsudoers = []data_bag('users').each do |user_name|u = data_bag_item('users', user_name)if u['sudo_cmds']sudoers << u['id']endendtemplate "/etc/sudoers" dosource "sudoers.erb"mode 0440owner "root"group "root"variables(:sudoers => sudoers)endfile: sudoers.erb# User privilege specificationroot ALL=(ALL) ALL<% @sudoers.each do |user|cmds = data_bag_item('users/#{user}', 'sudo_cmds')cmds.each do |cmd| -%><%= user %> <%= cmd %><% endend -%>Here is the error i get when I try to do thisGenerated at Sat Oct 08 16:38:16 +0200 2011Chef::Mixin::Template::TemplateError:Chef::Mixin::Template::TemplateError (undefined method `data_bag_item' for #<Erubis::Context:0xb6ffcb64>) on line #12:10:11: <% @sudoers.each do |user|12: cmds = data_bag_item('users/#{user}', 'sudo_cmds')13:14: cmds.each do |cmd| -%>
Archive powered by MHonArc 2.6.16.