Created
March 7, 2023 16:36
-
-
Save JSONOrona/6a63c08b75fbeb1b15e945cbdc0fea44 to your computer and use it in GitHub Desktop.
Ruby Chef API example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'chef' | |
require 'chef/config' | |
require 'chef/server_api' | |
# Configure the Chef Infra Server API endpoint and credentials | |
Chef::Config.node_name = 'yourusername' | |
Chef::Config.client_key = '/path/to/your/client/key.pem' | |
Chef::Config.chef_server_url = 'https://yourchefserver.com/organizations/yourorg' | |
# Define the name and password of the user to create | |
username = 'newuser' | |
password = 'mypassword' | |
# Create a new Chef Infra Server user with the specified name and password | |
user = Chef::ServerAPI.new.create_user(username, password: password, admin: false) | |
puts "Created user '#{username}'" | |
# Delete the Chef Infra Server user with the specified name | |
Chef::ServerAPI.new.delete_user(username) | |
puts "Deleted user '#{username}'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment