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.

How to programmatically change Ambari admin password?

Solved Go to solution

How to programmatically change Ambari admin password?

New Contributor

I am working on automating the installation and provisioning of clusters, which includes installing Ambari and using a Blueprint via the API. This is all working fine, but I have one more thing which I'm having trouble with, and that is changing the Ambari password during the overall provisioning process (I'm referring to my process here, not the Ambari cluster creation process). What I do NOT want is to leave newly provisioned Ambari installs sitting around with the default "admin/admin" credentials, and I also can't have a human going in to change this every time.

I've tried the REST API, but even though the call appears to execute correctly (eg, no errors are returned), the new password never takes effect.

I thought about using the ambari-admin-password-reset command via ssh, but my Ambari install (using 2.1.0) doesn't appear to have that command. I've double checked that the agent is running, and I've tried it as the root user, and in every case, it yields a "command not found" error.

I also thought about using JDBC, connecting directly to Postgres, and munging the password directly, but I'm not sure which hash algorithm Ambari uses, and/or where it stores the salt (if one is used).

If anyone can provide any advice on how to make any or all of these approaches work, it would be greatly appreciated. Right now I'm about to tear my last hair out fighting with this.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to programmatically change Ambari admin password?

@Phillip Rhodes

- Suppose "joy" users password was earlier "joy123" and i want to change it to "joy321" then i would do the following.

curl -i -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"Users": { "user_name": "joy", "password": "joy321", "old_password": "admin"}}' http://kjss1:8080/api/v1/users/joy 

NOTE: Please make sure to choose the "old_password" as the admin's users password which you used in the "-u admin:admin" command. (please do not use "joy123" as old password of that user).

Once you are able to change the password for user "joy" using above Ambari API. Then you should be able to invoke the same Rest API from your Java Code as well using rest client APIs.

3 REPLIES 3

Re: How to programmatically change Ambari admin password?

@Phillip Rhodes

- Suppose "joy" users password was earlier "joy123" and i want to change it to "joy321" then i would do the following.

curl -i -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"Users": { "user_name": "joy", "password": "joy321", "old_password": "admin"}}' http://kjss1:8080/api/v1/users/joy 

NOTE: Please make sure to choose the "old_password" as the admin's users password which you used in the "-u admin:admin" command. (please do not use "joy123" as old password of that user).

Once you are able to change the password for user "joy" using above Ambari API. Then you should be able to invoke the same Rest API from your Java Code as well using rest client APIs.

Re: How to programmatically change Ambari admin password?

New Contributor

Interesting, that differs slightly from the other documentation on the REST API I found here:

https://community.hortonworks.com/articles/50102/managing-ambari-users-and-groups-using-rest-api.htm...

At any rate, I appreciate the information and I will give that a try shortly. Thanks!

Re: How to programmatically change Ambari admin password?

New Contributor

@jss - thank you, that worked. Apparently the documentation I was looking at was incorrect or outdated

or something. In either case, setting up the JSON the way you showed worked like a champ!

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