<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Determine Ambari Host and Cluster Name from command line for configs.sh in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Determine-Ambari-Host-and-Cluster-Name-from-command-line-for/m-p/167205#M37094</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/11398/zachkirsch.html" nodeid="11398"&gt;@Zach Kirsch&lt;/A&gt;&lt;/P&gt;&lt;P&gt;1) I don't know what you mean by AMBARI_HOST? Is it where your ambari server is installed? From any of the agent hosts, you can find the server host from : /etc/ambari-agent/conf/ambari-agent.ini. &lt;/P&gt;&lt;P&gt;Look for the entry [server]
hostname=$SERVER_HOST&lt;/P&gt;&lt;P&gt;2) Are you ok using API? &lt;/P&gt;&lt;P&gt;You can get the cluster name by running :&lt;/P&gt;&lt;P&gt;curl --user admin:admin &lt;A href="http://$AMBARI_HOST:8080/api/v1/clusters/" target="_blank"&gt;http://$AMBARI_HOST:8080/api/v1/clusters/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;This will return you a response of the type :&lt;/P&gt;&lt;PRE&gt;{ "href" : "http://$AMBARI_HOST:8080/api/v1/clusters/", "items" : [ { "href" : "http://$AMBARI_HOST:8080/api/v1/clusters/clustername", "Clusters" : { "cluster_name" : "clustername", "version" : "version" } } ]}&lt;/PRE&gt;&lt;P&gt;You may then extract the cluster name.&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
    <pubDate>Sat, 06 Aug 2016 09:42:50 GMT</pubDate>
    <dc:creator>sbhat</dc:creator>
    <dc:date>2016-08-06T09:42:50Z</dc:date>
    <item>
      <title>Determine Ambari Host and Cluster Name from command line for configs.sh</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Determine-Ambari-Host-and-Cluster-Name-from-command-line-for/m-p/167204#M37093</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm writing a script that will set up the necessary classpath on a Spark cluster managed by Ambari.&lt;/P&gt;&lt;P&gt;Originally, I had a script that would just edit /etc/spark/conf/spark-defaults.conf directly. However, as discussed &lt;A target="_blank" href="https://community.hortonworks.com/questions/43587/spark-defulatsconf-constantly-being-overwritten.html"&gt;here&lt;/A&gt;, that was bad solution since Ambari regularly overwrites that file with whatever configuration is registered with Ambari.&lt;/P&gt;&lt;P&gt;Therefore, I am now using the configs.sh script as described &lt;A href="https://cwiki.apache.org/confluence/display/AMBARI/Modify+configurations#Modifyconfigurations-Editconfigurationusingconfigs.sh"&gt;here&lt;/A&gt; to make these adjustments.&lt;/P&gt;&lt;P&gt;I am looking for a way to determine the AMBARI_HOST and CLUSTER_NAME arguments via the command line. Here is what I have so far:&lt;/P&gt;&lt;PRE&gt;#!/usr/bin/env bash

ambari_host=  # TODO: some command to find this out
cluster_name= # TODO: some command to find this out
config_types=("spark.executor.extraClassPath" "spark.driver.extraClassPath")
phoenix_jar="$(ls /usr/hdp/current/phoenix-client/phoenix-*-client-spark.jar)"
sqljdbc_jar="$(ls /usr/share/java/sqljdbc*.jar)"
jars="$phoenix_jar:$sqljdbc_jar"

for config_type in "${config_types[@]}"; do
    /var/lib/ambari-server/resources/scripts/configs.sh \
	set "$ambari_host" "$cluster_name" spark-defaults "$config_type" "$jars"
done
&lt;/PRE&gt;&lt;P&gt;I can elaborate on anything that's unclear. Thanks in advance!&lt;/P&gt;&lt;P&gt;Edit: thank you everyone for the answers! I wish I could accept all of them.&lt;/P&gt;&lt;P&gt;For posterity, here's what I ended up with:&lt;/P&gt;&lt;PRE&gt;#!/usr/bin/env bash

ambari_user="$1"
ambari_password="$2"
ambari_port=8080

ambari_host="$(/opt/hostname_scripts/hostname.sh)"
cluster_name="$(curl -u ${ambari_user}:${ambari_password} -i -H 'X-Requested-By: ambari'  &lt;A href="http://$ambari_host:$ambari_port/api/v1/clusters" target="_blank"&gt;http://$ambari_host:$ambari_port/api/v1/clusters&lt;/A&gt; | sed -n 's/.*"cluster_name" : "\([^\"]*\)".*/\1/p')"

config_types=("spark.executor.extraClassPath" "spark.driver.extraClassPath")

phoenix_jar="$(ls /usr/hdp/current/phoenix-client/phoenix-*-client-spark.jar)"
sqljdbc_jar="$(ls /usr/share/java/sqljdbc*.jar)"
jars="$phoenix_jar:$sqljdbc_jar"

for config_type in "${config_types[@]}"; do
    /var/lib/ambari-server/resources/scripts/configs.sh -u "$ambari_user" -p "$ambari_password" -port "$ambari_port" set "$ambari_host" "$cluster_name" spark-defaults "$config_type" "$jars" &amp;gt; /dev/null
done &lt;/PRE&gt;&lt;P&gt;&lt;A target="_blank" href="http://lecluster.delaurent.com/one-shot-backup-all-config-files-with-ambari-api/"&gt;This&lt;/A&gt; was also a valuable resource.&lt;/P&gt;&lt;P&gt;[1] &lt;A target="_blank" href="https://community.hortonworks.com/questions/43587/spark-defulatsconf-constantly-being-overwritten.html"&gt;https://community.hortonworks.com/questions/43587/spark-defulatsconf-constantly-being-overwritten.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;[2] &lt;A target="_blank" href="https://cwiki.apache.org/confluence/display/AMBARI/Modify+configurations#Modifyconfigurations-Editconfigurationusingconfigs.sh"&gt;https://cwiki.apache.org/confluence/display/AMBARI/Modify+configurations#Modifyconfigurations-Editconfigurationusingconfigs.sh&lt;/A&gt;&lt;/P&gt;&lt;P&gt;[3] &lt;A target="_blank" href="http://lecluster.delaurent.com/one-shot-backup-all-config-files-with-ambari-api/"&gt;http://lecluster.delaurent.com/one-shot-backup-all-config-files-with-ambari-api/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2016 05:37:46 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Determine-Ambari-Host-and-Cluster-Name-from-command-line-for/m-p/167204#M37093</guid>
      <dc:creator>zachkirsch</dc:creator>
      <dc:date>2016-08-06T05:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: Determine Ambari Host and Cluster Name from command line for configs.sh</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Determine-Ambari-Host-and-Cluster-Name-from-command-line-for/m-p/167205#M37094</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/11398/zachkirsch.html" nodeid="11398"&gt;@Zach Kirsch&lt;/A&gt;&lt;/P&gt;&lt;P&gt;1) I don't know what you mean by AMBARI_HOST? Is it where your ambari server is installed? From any of the agent hosts, you can find the server host from : /etc/ambari-agent/conf/ambari-agent.ini. &lt;/P&gt;&lt;P&gt;Look for the entry [server]
hostname=$SERVER_HOST&lt;/P&gt;&lt;P&gt;2) Are you ok using API? &lt;/P&gt;&lt;P&gt;You can get the cluster name by running :&lt;/P&gt;&lt;P&gt;curl --user admin:admin &lt;A href="http://$AMBARI_HOST:8080/api/v1/clusters/" target="_blank"&gt;http://$AMBARI_HOST:8080/api/v1/clusters/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;This will return you a response of the type :&lt;/P&gt;&lt;PRE&gt;{ "href" : "http://$AMBARI_HOST:8080/api/v1/clusters/", "items" : [ { "href" : "http://$AMBARI_HOST:8080/api/v1/clusters/clustername", "Clusters" : { "cluster_name" : "clustername", "version" : "version" } } ]}&lt;/PRE&gt;&lt;P&gt;You may then extract the cluster name.&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Sat, 06 Aug 2016 09:42:50 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Determine-Ambari-Host-and-Cluster-Name-from-command-line-for/m-p/167205#M37094</guid>
      <dc:creator>sbhat</dc:creator>
      <dc:date>2016-08-06T09:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: Determine Ambari Host and Cluster Name from command line for configs.sh</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Determine-Ambari-Host-and-Cluster-Name-from-command-line-for/m-p/167206#M37095</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/11398/zachkirsch.html" nodeid="11398"&gt;@Zach Kirsch&lt;/A&gt;&lt;P&gt;1)  To find out cluster_name, you can either use the api curl --user admin:admin &lt;STRONG&gt;&lt;A href="http://$AMBARI_SERVER:8080/api/v1/clusters/" target="_blank"&gt;http://$AMBARI_SERVER:8080/api/v1/clusters/&lt;/A&gt;&lt;/STRONG&gt; as mentioned by Shreya,&lt;/P&gt;&lt;P&gt;Or you can query the database for table 'clusters' as below :&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select cluster_name from clusters;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;2) If you are looking to find out ambari server host, then as &lt;A rel="user" href="https://community.cloudera.com/users/1902/sbhat.html" nodeid="1902"&gt;@sbhat&lt;/A&gt; mentioned, you can grep ambari-agent.ini. Below command would do :&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;grep "hostname" /etc/ambari-agent/conf/ambari-agent.ini&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;But if you are looking for the host on which particular spark component is installed, then please use this api :&lt;/P&gt;&lt;P&gt;curl --user admin:admin &lt;STRONG&gt;&lt;A href="http://$AMBARI_SERVER:8080/api/v1/clusters/&amp;lt;cluster_name&amp;gt;/" target="_blank"&gt;http://$AMBARI_SERVER:8080/api/v1/clusters/&amp;lt;cluster_name&amp;gt;/&lt;/A&gt;&lt;/STRONG&gt;&lt;STRONG&gt;services/SPARK/&amp;lt;component_name&amp;gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;From the response, parse the json for the field 'host_components'&lt;/P&gt;</description>
      <pubDate>Sun, 07 Aug 2016 02:11:08 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Determine-Ambari-Host-and-Cluster-Name-from-command-line-for/m-p/167206#M37095</guid>
      <dc:creator>ssharma</dc:creator>
      <dc:date>2016-08-07T02:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Determine Ambari Host and Cluster Name from command line for configs.sh</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Determine-Ambari-Host-and-Cluster-Name-from-command-line-for/m-p/167207#M37096</link>
      <description>&lt;P&gt; &lt;A rel="user" href="https://community.cloudera.com/users/11398/zachkirsch.html" nodeid="11398"&gt;@Zach Kirsch&lt;/A&gt; here is how I usually detect the cluster name using parsing the json output via sed&lt;/P&gt;&lt;PRE&gt;export SERVICE=ZEPPELIN
export PASSWORD=admin
export AMBARI_HOST=localhost

#detect name of cluster
output=`curl -u admin:$PASSWORD -i -H 'X-Requested-By: ambari'  &lt;A href="http://$AMBARI_HOST:8080/api/v1/clusters`" target="_blank"&gt;http://$AMBARI_HOST:8080/api/v1/clusters`&lt;/A&gt;

CLUSTER=`echo $output | sed -n 's/.*"cluster_name" : "\([^\"]*\)".*/\1/p'`

echo $CLUSTER&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Aug 2016 08:34:01 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Determine-Ambari-Host-and-Cluster-Name-from-command-line-for/m-p/167207#M37096</guid>
      <dc:creator>abajwa</dc:creator>
      <dc:date>2016-08-08T08:34:01Z</dc:date>
    </item>
    <item>
      <title>Re: Determine Ambari Host and Cluster Name from command line for configs.sh</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Determine-Ambari-Host-and-Cluster-Name-from-command-line-for/m-p/167208#M37097</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/11398/zachkirsch.html" nodeid="11398"&gt;@Zach Kirsch&lt;/A&gt;&lt;P&gt;You can get Ambari server hostname from ambari-agent.ini file.&lt;/P&gt;&lt;P&gt;example:&lt;/P&gt;&lt;PRE&gt;[root@kknode3 ~]# cat /etc/ambari-agent/conf/ambari-agent.ini |grep -i host
hostname = kknode1.openstacklocal&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Aug 2016 10:24:40 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Determine-Ambari-Host-and-Cluster-Name-from-command-line-for/m-p/167208#M37097</guid>
      <dc:creator>KuldeepK</dc:creator>
      <dc:date>2016-08-08T10:24:40Z</dc:date>
    </item>
  </channel>
</rss>

