title: Creating multiple users in chef using Chef Vault
body: <p>I have the following user credentials in my chef vault</p>
  
  <pre><code>$ knife vault show testusers
  user1
  user2
  user3
  </code></pre>
  
  <p>The content of each individual user looks like this:</p>
  
  <pre><code>knife vault show testusers user1
  comment:  user one
  id:       user1
  password: secretp@ss
  shell:    /bin/bash
  </code></pre>
  
  <p>I am trying to write a recipe that will loop through my <code>testuser</code> vault and create users based on each vault item's ID. That way i can easily update the <code>testuser</code> vault with new users and rerun the recipe in order to add users in the future.</p>
  
  <p>Here is a copy of the recipe i have created thus far but it isn't working</p>
  
  <pre><code>chef_gem 'chef-vault' do
    compile_time true if respond_to?(:compile_time)
  end
  
  require 'chef-vault'
  
  if node['testcookbook']['testusers'] == true then
      users = data_bag(node['testcookbook']['testusers'])
      users.each do |id|
          user = ChefVault::Item.load(node["testcookbook","testusers"], id)
          testusers user['id'] do
              comment user['comment']
              shell user['shell']
              password user['password']
          end
      end
  </code></pre>
  
  <p>Can someone please tell me what i am doing wrong here? Everything seems to look fine from the numerous research i have done.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I tried your solution and the following error message. </p>
  
  <pre><code>Chef::Exceptions::InvalidDataBagName
  
  ------------------------------------
  
  DataBags must have a name matching /^[\.\-[:alnum:]_]+$/, you gave ""
  
  chef_gem 'chef-vault' do
    compile_time true if respond_to?(:compile_time)
  end
  require 'chef-vault'
  
  17&gt;&gt;    users = data_bag(node['testcookbook']['testusers']).delete_if {|x| x.include? "_keys" }
       users.each do |id|
             user = ChefVault::Item.load(node["testcookbook","testusers"], id)
              testcookbook testusers['id'] do
                     comment testusers['comment']
                     uid testusers['uid']
                     shell testusers['shell']
                     password testusers['password']
                end 
  </code></pre>
  
  <blockquote>
    <p>[2016-08-22T19:24:58-04:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out<br>
    [2016-08-22T19:24:58-04:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report<br>
    [2016-08-22T19:24:58-04:00] ERROR: DataBags must have a name matching /^[.-[:alnum:]_]+$/, you gave ""<br>
    [2016-08-22T19:24:58-04:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)`</p>
  </blockquote>