Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

rest api to create ambari user dynamically

Highlighted

rest api to create ambari user dynamically

i want to write script which will ask username at run time which you want to create, that username should be passed to ambari user creation rest api

1 REPLY 1

Re: rest api to create ambari user dynamically

Super Mentor

@Anurag Mishra

I just created & tested the following kind of "/tmp/ambari_user_create.sh" to create ambari user on Ambari 2.5.1 and it worked well.

# cat /tmp/ambari_user_create.sh

echo -n "Enter ambari user me: "
read -s ambari_new_user_name

echo""

echo -n "Enter ambari user password: "
read -s ambari_new_user_pwd

echo "Creating Ambari User : $ambari_new_user_name"
curl -iv -u $Ambariuser:$ambaripass -H "X-Requested-By: ambari" -X POST -d '{"Users/user_name":"'${ambari_new_user_name}'","Users/password":"'${ambari_new_user_pwd}'","Users/active":"true","Users/admin":"false"}'  http://localhost:8080/api/v1/users

.

Example Output:

# chmod 755 /tmp/ambari_user_create.sh

# /tmp/ambari_user_create.sh
Enter ambari user me: 
Enter ambari user password: 

* About to connect() to localhost port 8080 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8080 (#0)
* Server auth using Basic with user 'admin'
> POST /api/v1/users HTTP/1.1
> Authorization: Basic YWRtaW46YWRtaW4=
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: localhost:8080
> Accept: */*
> X-Requested-By: ambari
> Content-Length: 90
> Content-Type: application/x-www-form-urlencoded
> 
< HTTP/1.1 201 Created
HTTP/1.1 201 Created
< X-Frame-Options: DENY
X-Frame-Options: DENY
< X-XSS-Protection: 1; mode=block
X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
X-Content-Type-Options: nosniff
< Cache-Control: no-store
Cache-Control: no-store
< Pragma: no-cache
Pragma: no-cache
< Set-Cookie: AMBARISESSIONID=187qkhfpj2vao163ramjwnuv34;Path=/;HttpOnly
Set-Cookie: AMBARISESSIONID=187qkhfpj2vao163ramjwnuv34;Path=/;HttpOnly
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
< User: admin
User: admin
< Content-Type: text/plain
Content-Type: text/plain
< Content-Length: 0
Content-Length: 0
< Server: Jetty(8.1.19.v20160209)
Server: Jetty(8.1.19.v20160209)

< 
* Connection #0 to host localhost left intact
* Closing connection #0

.

Don't have an account?
Coming from Hortonworks? Activate your account here