Blank Pad Development

A photo of Jon

Hello There

I’m Jon, a web developer working for Hubbub to make it easier for people to buy great food from their local shops.

This is where I occassionally write about what I'm doing, and make a note of anything I'm likely to want to Google in the future!

Resetting a user's password in Chef

This morning in #chef someone had locked themselves out of their WebUI admin account, and wanted to know how to reset the password.

So long you have knife set up with an admin account locally, this should do the trick:

unless ARGV[0] && ARGV[1]
  puts "Usage: set_password.rb username password"
  exit 1
end

require 'chef'
require 'chef/config'
require 'chef/webui_user'

Chef::Config.from_file(File.expand_path("/.chef/knife.rb"))

user = Chef::WebUIUser.load(ARGV[0])
if user
  user.set_password(ARGV[1])
  user.save
else
  puts "Could not find user #{ARGV[0]}."
  exit 2
end

Put it in a file, and then run ruby set_password.rb admin newpassword. If it doesn’t say anything, it worked.

blog comments powered by Disqus