Support Questions
Find answers, ask questions, and share your expertise
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


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


Re: rest api to create ambari user dynamically

Super Mentor

@Anurag Mishra

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

# cat /tmp/

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


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/

# /tmp/
Enter ambari user me: 
Enter ambari user password: 

* About to connect() to localhost port 8080 (#0)
*   Trying connected
* Connected to localhost ( 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