Skip to main content
narendra_klu9
Silver ⭐️⭐️⭐️
Jul 5, 2019 1:31 PM UTC
Solved

Is there any way to pass parameters to a custom script in ambari ?

I'm working on a POC to take NN metadata backup. For this, i'm compressing the NN's metadata using a custom script that i will call through ambari API. (https://community.hortonworks.com/articles/139788/running-custom-scripts-through-ambari.html) . If i simply hardcode the datadirectory name it will work. However, i'm looking to pass them as an argument while submitting the request. Anyone aware of the method ?

akhilsnaik
Gold ⭐️⭐️⭐️
Jul 5, 2019 3:38 PM UTC

Hi @Narendra Neerukonda,


As the Article Says :

Note: You can add comma separated inputs if you need any inputs for the script.

you can actually pass the parameters to the script like this :

curl -u <username>:<password> -X POST -H 'X-Requested-By:ambari' -d'{"RequestInfo":{"context":"Execute my action", "action":"my_action", "parameters" : {"my_input" : "value"}}, "Requests/resource_filters":[{"service_name":"", "component_name":"", "hosts":"<comma_separated_host_names>"}]' http://<ambari_host>:<port>/api/v1/clusters/<cluster_name>/requests

Where "my_input" is paramter name and "value" is the value to be passed.

Hope this helps. Please accept answer and vote up if it did.


4 replies

akhilsnaik
Gold ⭐️⭐️⭐️
Gold ⭐️⭐️⭐️
Jul 5, 2019 3:38 PM UTC

Hi @Narendra Neerukonda,


As the Article Says :

Note: You can add comma separated inputs if you need any inputs for the script.

you can actually pass the parameters to the script like this :

curl -u <username>:<password> -X POST -H 'X-Requested-By:ambari' -d'{"RequestInfo":{"context":"Execute my action", "action":"my_action", "parameters" : {"my_input" : "value"}}, "Requests/resource_filters":[{"service_name":"", "component_name":"", "hosts":"<comma_separated_host_names>"}]' http://<ambari_host>:<port>/api/v1/clusters/<cluster_name>/requests

Where "my_input" is paramter name and "value" is the value to be passed.

Hope this helps. Please accept answer and vote up if it did.


Translate
narendra_klu9
Silver ⭐️⭐️⭐️
Jul 8, 2019 5:02 PM UTC

My previous comment is still under moderation but the solution is: Apparently, it's mandatory to pass value for service_name and component_name.

Translate
ask_bill_brooks
Platinum ⭐️
Platinum ⭐️
Jul 7, 2019 12:36 AM UTC

The above question and the entire response thread below was originally posted in the Community Help track. On Sat Jul 6 17:30 UTC 2019, a member of the HCC moderation staff moved it to the Cloud & Operations track. The Community Help Track is intended for questions about using the HCC site itself, not technical questions.

Translate
Bill Brooks, Community Moderator Was your question answered? Make sure to mark the answer as the accepted solution. If you find a reply useful, say thanks by clicking on the thumbs up button.