fnichol/chef-user

Unable to get data_bag recipe to work

Closed this issue · 3 comments

I've been trying to take advantage of the data_bags recipe but wasn't able to get it to work. I'm provisioning a vm using vagrant and hosted chef.

I may not be able to get it to work because I'm not understanding how it is suppose to work but following the data bags page from the opscode wiki (http://wiki.opscode.com/display/chef/Data+Bags) I was able to change the data_bags recipe to the following and then it worked.

# data_bag.rb
users = data_bag("users")

users.each do |i|
  u = data_bag_item("users", i.gsub(/[.]/, '-'))
  username = u['username'] || u['id']

  user_account username do
    %w{comment uid gid home shell password system_user manage_home create_group
        ssh_keys ssh_keygen}.each do |attr|
      send(attr, u[attr]) if u[attr]
    end
    action u['action'].to_sym if u['action']
  end
end

Obviously this specifies the users data bag which I think you were trying to avoid. I may just not understand how I'm suppose to specify the data bag using the original code. Thoughts on what my problem? I just need some more direction here.

Here is what my data bag looks like

data_bags/
|---users/
|--- deployuser.json

deployer.json is below

{
  "id"        : "deployer",
  "comment"   : "Deploy User",
  "ssh_keys"  : "ssh-rsa AAAAB3N..."
}

I figured it out. The piece I was missing was to add node['users'] = ['deployer'].

Oh right, you are correct. I debated about that bit of config but I found that if you have enough nodes across an infrastructure you might not always want every single user installed on every single node. Otherwise it's working for you? Good to close?

Hopefully we're good here, if not just re-open!