Bulk user invite/add in Chef organization


Can we add multiple users in chef organization in one go? We need to do this from chef workstation, as we don’t have access on chef server. So, chef-server-ctl won’t work for us.
Please suggest.


@Neerajjh There is no bulk creation through knife. But you can still create bulk creation through customized orchestration.

You can try this.

  1. Create users.json file add have the following sample users info
  "suthir": {
    "display_name": "Suthir Kannan",
    "first_name": "Suthir",
    "last_name": "Kannan",
    "email": "ksuthirperumal@gmail.com",
    "password": "d28fef1f2a8089b516c0e4287deec8f7"

Running the following ruby script, it will create all the users mentioned in the json file.

#!/usr/bin/env ruby

require 'json'

users = JSON.parse(File.read('users.json'))

users.each do | uid, user|
  command = "knife user create #{uid} '#{user['display_name']}' '#{user['first_name']}' '#{user['last_name']}' '#{user['email']}' '#{user['password']}' -f #{uid} -k #{uid}.pub --disable-editing"
  puts "User account created for #{user['email']}"

Hope this helps!


Thanks Suthir. This is really helpful.


If I may say? It’s not loading them in one go, which was the original question. It’s running a loop that does them one at a time, and it’s reading them from a json hash.

There’s no compelling need for a json hash file to feed this. Since the “command” is a system command, anyway, the data could be a tab-separated variable and read from stdin by a loop in /bin/bash or /bin/sh, which could also provide easier opportunities to establish an opportunity to filter the data, or to reread the list of existing users, or to feed the data from a database lookup. Sometimes it’s not worth transforming the original data into json, even though it’s a common place way to read it into chef.


Thanks for your input Niko!