Community Articles

Find and share helpful community-sourced technical articles.
Labels (1)
avatar
Expert Contributor

Most frequently there are questions on how to add/delete groups/users from Ambari. This document describes how to add/delete ambari's local users and groups (Delete applies to LDAP users/groups as well).

This document should give a consolidated list of rest calls to manage users/groups.

Following are the steps for end-to-end creation/updating users/groups using ambari REST API.

1) Creating a user :

curl -iv -u admin:admin -H "X-Requested-By: ambari" -X POST -d '{"Users/user_name":"{USER}","Users/password":"{PASSWORD}","Users/active":"{ISACTIVE}","Users/admin":"{ISADMIN}"}' http://ambari-server:8080/api/v1/users

2) Change password of user :

curl -iv -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"Users/password":"{UPDATED_PASSWORD}"}' http://ambari-server:8080/api/v1/users/{USER}

3) Toggle user's admin status:

curl -iv -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"Users/admin":"{true/false}"}' http://ambari-server:8080/api/v1/users/{USER}

4) Creating a group :

curl -iv -u admin:admin -H "X-Requested-By: ambari"-X POST -d '{"Groups/group_name":"{GROUP_NAME}"}' http://ambari-server:8080/api/v1/groups

5) Adding a user to a (new) group :

curl -iv -u admin:admin -H "X-Requested-By: ambari"-X PUT -d '[{"MemberInfo/user_name":"{USER_NAME}","MemberInfo/group_name":"{GROUP_NAME}"}]' http://ambari-server:8080/api/v1/groups/{GROUP_NAME}/members

This will delete users from the group if the group exists.

6) Adding user to the users list in a group :

curl -iv -u admin:admin -H "X-Requested-By: ambari"-X POST -d '[{"MemberInfo/user_name":"{USER_NAME}","MemberInfo/group_name":"{GROUP_NAME}"}]' http://ambari-server:8080/api/v1/groups/{GROUP_NAME}/members

7) Get all users :

curl -iv -u admin:admin -X GET http://ambari-server:8080/api/v1/users

😎 Get all groups :

curl -iv -u admin:admin -X GET http://ambari-server:8080/api/v1/groups

9) Get members of a group :

curl -iv -u admin:admin -X GET http://ambari-server:8080/api/v1/groups/{GROUP_NAME}/members

10) Get user info :

curl -iv -u admin:admin -X GET http://ambari-server:8080/api/v1/groups/{GROUP_NAME}

11) Get group info :

curl -iv -u admin:admin -X GET http://ambari-server:8080/api/v1/users/{USER_NAME}

12) Removing a user from the users list in a group :

To remove a user from a group, request a PUT with request body having a list of users that should be included in the group (Exclude ones that need to be deleted)

curl -iv -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '[{"MemberInfo/user_name":"{USER_NAME1}","MemberInfo/group_name":"{GROUP_NAME}"},{"MemberInfo/user_name":"{USER_NAME2}","MemberInfo/group_name":"{GROUP_NAME}"}]' http://ambari-server:8080/api/v1/groups/{GROUP_NAME}/members

13) Delete a user using REST API :

curl -iv -u admin:admin -H "X-Requested-By: ambari"-X DELETE http://ambari-server:8080/api/v1/users/{USER_NAME}

14) Delete a group using REST API :

curl -iv -u admin:admin -H "X-Requested-By: ambari"-X DELETE http://ambari-server:8080/api/v1/groups/{GROUP_NAME}
3,962 Views
Comments
avatar
Super Guru

@sbhat

Is any of this documented somewhere? Looking at: https://github.com/apache/ambari/blob/trunk/ambari-server/docs/api/v1/index.md I don't see any reference to creating users.