Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

Execute custom scripts on hosts

avatar

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>