Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Execute custom scripts on hosts

avatar
New Contributor

Is there a way to execute custom scripts on all hosts from ambari server, or any other process/service?

1 ACCEPTED SOLUTION

avatar
Super Collaborator

Yes, I believe that you can. There is a folder which ships with Ambari Server in /var/lib/ambari-server/resources/custom_actions/scripts. You can have Ambari execute these scripts on the agents. For example, when you create a new cluster, Ambari "checks the hosts" for things like memory, OS, problems. This script is the check_host.py script. It's invoked like:

{
  "RequestInfo": {
    "action": "check_host",
    "context": "Check host",
    "parameters": {
      "check_execute_list": "host_resolution_check",
      "jdk_location": "http://192.168.64.1:8080/resources/",
      "threshold": "20",
      "hosts": "c6401.ambari.apache.org,c6402.ambari.apache.org,c6403.ambari.apache.org"
    }
  },
  "Requests/resource_filters": [
    {
      "hosts": "c6401.ambari.apache.org,c6402.ambari.apache.org,c6403.ambari.apache.org"
    }
  ]
}

Where "action" is the name of the script. The action is defined in /var/lib/ambari-server/resources/custom_action_definitions/system_action_definitions.xml like so:

  <actionDefinition>
    <actionName>check_host</actionName>
    <actionType>SYSTEM</actionType>
    <inputs/>
    <targetService/>
    <targetComponent/>
    <defaultTimeout>60</defaultTimeout>
    <description>General check for host</description>
    <targetType>ANY</targetType>
    <permissions>HOST.ADD_DELETE_HOSTS</permissions>
  </actionDefinition>

View solution in original post

2 REPLIES 2

avatar
Master Mentor

If you're using Hortonworks Data Cloud, HDInsights or Cloudbreak, you can leverage node recipes to execute custom actions. For on premise clusters there is nothing out of the box you can leverage except for extending Ambari to custom service via API. If you're running RPM derivative OS, you can use Ansible as RHEL sells enterprise support with OS. For home-baked solution, you can still use Ansible, Chef, Puppet, CFEngine or Salt Stack across all OS flavors but it has nothing to do with Ambari.

avatar
Super Collaborator

Yes, I believe that you can. There is a folder which ships with Ambari Server in /var/lib/ambari-server/resources/custom_actions/scripts. You can have Ambari execute these scripts on the agents. For example, when you create a new cluster, Ambari "checks the hosts" for things like memory, OS, problems. This script is the check_host.py script. It's invoked like:

{
  "RequestInfo": {
    "action": "check_host",
    "context": "Check host",
    "parameters": {
      "check_execute_list": "host_resolution_check",
      "jdk_location": "http://192.168.64.1:8080/resources/",
      "threshold": "20",
      "hosts": "c6401.ambari.apache.org,c6402.ambari.apache.org,c6403.ambari.apache.org"
    }
  },
  "Requests/resource_filters": [
    {
      "hosts": "c6401.ambari.apache.org,c6402.ambari.apache.org,c6403.ambari.apache.org"
    }
  ]
}

Where "action" is the name of the script. The action is defined in /var/lib/ambari-server/resources/custom_action_definitions/system_action_definitions.xml like so:

  <actionDefinition>
    <actionName>check_host</actionName>
    <actionType>SYSTEM</actionType>
    <inputs/>
    <targetService/>
    <targetComponent/>
    <defaultTimeout>60</defaultTimeout>
    <description>General check for host</description>
    <targetType>ANY</targetType>
    <permissions>HOST.ADD_DELETE_HOSTS</permissions>
  </actionDefinition>