Created
March 3, 2023 22:55
-
-
Save JSONOrona/cd9b7b2495d11349244d595e90b3adee to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Parse command line arguments | |
while getopts ":u:p:" opt; do | |
case ${opt} in | |
u ) | |
USERNAME=$OPTARG | |
;; | |
p ) | |
PASSWORD=$OPTARG | |
;; | |
\? ) | |
echo "Usage: $0 [-u USERNAME] [-p PASSWORD]" | |
exit 1 | |
;; | |
esac | |
done | |
# Set default values for variables | |
CHEF_SERVER="https://chef-server.example.com/organizations/myorg" | |
ADMIN_USER="admin" | |
ADMIN_KEY="/etc/opscode/admin.pem" | |
# Add user as admin to organization | |
echo "Adding user to organization as admin..." | |
chef-server-ctl user-create $USERNAME Firstname Lastname [email protected] $PASSWORD --filename /etc/opscode/$USERNAME.pem | |
chef-server-ctl org-user-add myorg $USERNAME --admin | |
# Create client key | |
echo "Creating client key..." | |
chef-server-ctl create-client-key $USERNAME $USERNAME --file /etc/opscode/$USERNAME.pem --key-name $USERNAME | |
# Add client to organization | |
echo "Adding client to organization..." | |
chef-server-ctl add-client-to-group myorg $USERNAME | |
echo "User $USERNAME has been successfully added as an admin to organization myorg." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment