Created on 12-07-2016 02:35 PM - edited 08-19-2019 01:12 AM
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
But i got this error below. Please can you help me? Thanks
Created 12-07-2016 03:13 PM
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"
Created 12-07-2016 02:41 PM
Assuming ambari2 user can stop the services,
Why don't you try using
ambari-agent stop
instead of
systemctl stop ambari-agent.service
Created 12-07-2016 02:43 PM
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.
Created 12-07-2016 02:43 PM
Are you running ambari-agent as "root" user or "ambari2" user?
Created 12-07-2016 02:51 PM
@Karthik Narayanan i run ambari agent with root. Ambari2 user have no privilige to do that
Created 12-07-2016 03:05 PM
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
Created 12-07-2016 02:43 PM
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.
Created 12-07-2016 02:51 PM
no it's a mistake. It's ambari2 user not ambari
Created 12-07-2016 03:13 PM
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"
Created 12-07-2016 03:26 PM
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: