The following example shows how to install multiple components on multiple hosts.
Add components to hosts. The components will show up on the Ambari web UI in the host view with the Install Pending... state.
curl -v -k -i -u admin:admin -H 'X-Requested-By: ambari' -X POST -d ' { "RequestInfo":{ "query":"Hosts/host_name.in(c6401.ambari.apache.org,c6402.ambari.apache.org,c6403.ambari.apache.org)" }, "Body":{ "host_components":[ { "HostRoles":{ "component_name":"HBASE_REGIONSERVER" } }, { "HostRoles":{ "component_name":"DATANODE" } }, { "HostRoles":{ "component_name":"TEZ_CLIENT" } } ] } }' $HTTP_PROTOCOL://$CONSOLE_NODE:$PORT/api/v1/clusters/$CLUSTER/hosts
Install components on hosts
curl -v -k -i -u admin:admin -H 'X-Requested-By: ambari' -X PUT --data ' { "RequestInfo":{ "context":"Install components on hosts" }, "Body":{ "HostRoles":{ "state":"INSTALLED" } } }' "$HTTP_PROTOCOL://$CONSOLE_NODE:$PORT/api/v1/clusters/$CLUSTER/host_components?HostRoles/component_name.in(DATANODE,HBASE_REGIONSERVER,TEZ_CLIENT)&HostRoles/host_name.in(c6401.ambari.apache.org,c6402.ambari.apache.org,c6403.ambari.apache.org)"
Alternatively, you can kick off an install of components via a bit more implicit REST API call that kicks off installation on all hosts.
curl -v -k -i -u admin:admin -H 'X-Requested-By: ambari' -X PUT -d ' { "HostRoles": { "state":"INSTALLED" } } ' $HTTP_PROTOCOL://$CONSOLE_NODE:$PORT/api/v1/clusters/$CLUSTER/host_components?HostRoles/state=INIT
Start components on hosts
curl -v -k -i -u admin:admin -H 'X-Requested-By: ambari' -X PUT --data ' { "RequestInfo":{ "context":"Start components on hosts" }, "Body":{ "HostRoles":{ "state":"STARTED" } } }' "$HTTP_PROTOCOL://$CONSOLE_NODE:$PORT/api/v1/clusters/$CLUSTER/host_components?HostRoles/component_name.in(DATANODE,HBASE_REGIONSERVER,TEZ_CLIENT)&HostRoles/host_name.in(c6401.ambari.apache.org,c6402.ambari.apache.org,c6403.ambari.apache.org)"