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 can i write a script to automate stop of all ambari server

Solved Go to solution
Highlighted

How can i write a script to automate stop of all ambari server

Hello,

I work actualy with HDP 2.5 and my cluster have 25 nodes. I try to automate all my script in partuclar a script to start and stop all ambari agent.

My cluster are not install with root but with username ambari.

i try ssh with this command

hosts=$(curl -s -u admin:admin -H 'X-Requested-By:ambari' -i -k -X GET ${AMBARI_HSTNAME}:8080/api/v1/clusters/muclusterName/hosts | grep '"host_name"' | cut -d'"' -f4)
print $hosts

for host in $hosts
do
     ssh ambari2@$host "systemctl stop ambari-agent.service"
     print DONE for $host ...............................
done

10155-ambariagent-error.png

But i got this error below.

Please can you help me? 
Thanks
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: How can i write a script to automate stop of all ambari server

Expert Contributor

to be clear

modify vi /etc/sudoers in each node to be allow ambari2 to sudo without password.

ambari2 ALL=(ALL) NOPASSWD: ALL

then change ssh command "ssh -t ambari2@host "sudo systemctl ambari-agent restart"

View solution in original post

9 REPLIES 9
Highlighted

Re: How can i write a script to automate stop of all ambari server

Rising Star

@Baruch AMOUSSOU DJANGBAN

Assuming ambari2 user can stop the services,

Why don't you try using

ambari-agent stop

instead of

systemctl stop ambari-agent.service	
Highlighted

Re: How can i write a script to automate stop of all ambari server

Expert Contributor

you have ambari2 as the username, may be you need to use ambari. Also, has ambari user been setup with password less ssh to the other nodes.

Highlighted

Re: How can i write a script to automate stop of all ambari server

@Baruch AMOUSSOU DJANGBAN

Are you running ambari-agent as "root" user or "ambari2" user?

Highlighted

Re: How can i write a script to automate stop of all ambari server

@Karthik Narayanan i run ambari agent with root. Ambari2 user have no privilige to do that

Highlighted

Re: How can i write a script to automate stop of all ambari server

Expert Contributor

in your ssh command ssh ambari2@$host, you have ambari2 and in your question you say you installed as ambari, so just wanted to confirm ambari2 is correct.

so if you are able to ssh correctly, you have two issue,

i think ambari-agent will run as root, so you need to do a sudo.

so u have to pass -t to you ssh command. ssh -t ambari2@host (alternately you can disable requiretty in /etc/sudoers ).

So in /etc/sudoers of each remote machine, you have to enable ambari to be able to run command without password.

like this

ambari2 ALL=(ALL) NOPASSWD: ALL

Re: How can i write a script to automate stop of all ambari server

Expert Contributor

you have ambari2 as the username, may be you need to use ambari. Also, has ambari user been setup with password less ssh to the other nodes.

Highlighted

Re: How can i write a script to automate stop of all ambari server

no it's a mistake. It's ambari2 user not ambari

Highlighted

Re: How can i write a script to automate stop of all ambari server

Expert Contributor

to be clear

modify vi /etc/sudoers in each node to be allow ambari2 to sudo without password.

ambari2 ALL=(ALL) NOPASSWD: ALL

then change ssh command "ssh -t ambari2@host "sudo systemctl ambari-agent restart"

View solution in original post

Highlighted

Re: How can i write a script to automate stop of all ambari server

@Baruch AMOUSSOU DJANGBAN

you can do this as well.If you have installed the Cluster Shell in cluster, we can perform below simple steps to stop and start

-----------------------------------

#!/bin/sh

clush -g all ambari-agent restart

-------------------------------------------

Refer below link for more info about open source Cluster shell:

https://github.com/cea-hpc/clustershell/downloads

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