How to edit the "cluster-env.xml" entries using Ambari Rest APIs
Step1). Get all the properties from the below command: (Here : "http://jss1:8080" is the URL where ambari server is running)
curl --user admin:admin -i -H 'X-Requested-By: ambari' -X GET http://jss1:8080/api/v1/clusters/JoyCluster/configurations?type=cluster-env\&tag=version1
Step2). Save the output from above command to a file. Or just open the URL in browser and save it to a file:
http://jss1:8080/api/v1/clusters/JoyCluster/configurations?type=cluster-env&tag=version1
.
For example here i got the following output from the above URL:
{
"href" : "http://jss1:8080/api/v1/clusters/JoyCluster/configurations?type=cluster-env&tag=version1",
"items" : [
{
"href" : "http://jss1:8080/api/v1/clusters/JoyCluster/configurations?type=cluster-env&tag=version1",
"tag" : "version1",
"type" : "cluster-env",
"version" : 1,
"Config" : {
"cluster_name" : "JoyCluster",
"stack_id" : "HDP-2.4"
},
"properties" : {
"fetch_nonlocal_groups" : "true",
"ignore_groupsusers_create" : "false",
"kerberos_domain" : "EXAMPLE.COM",
"managed_hdfs_resource_property_names" : "",
"override_uid" : "true",
"repo_suse_rhel_template" : "[{{repo_id}}]\nname={{repo_id}}\n{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}\n\npath=/\nenabled=1\ngpgcheck=0",
"repo_ubuntu_template" : "{{package_type}} {{base_url}} {{components}}",
"security_enabled" : "false",
"smokeuser" : "ambari-qa",
"smokeuser_keytab" : "/etc/security/keytabs/smokeuser.headless.keytab",
"user_group" : "hadoop"
}
}
]
}
Here notice that the value of ["ignore_groupsusers_create" : "false"] That we are going to change to "true"
Step3). Create a fresh file with any name (like: /tmp/configurations.txt) with the following content:
{
"Clusters" : {
"desired_configs" : {
"type" : "cluster-env",
"tag" : "version2",
"properties" : {
// *** WE WILL NEED TO ADD OUR PROPERTIES HERE FROM THE OUTPUT OF STEP2 OUTPUT *** //
}
}
}
}
Step4). Now for example we edited the file "/tmp/configurations.txt" like following (notice: "ignore_groupsusers_create" : "true"):
{
"Clusters" : {
"desired_configs" : {
"type" : "cluster-env",
"tag" : "version2",
"properties" : {
"fetch_nonlocal_groups" : "true",
"ignore_groupsusers_create" : "true",
"kerberos_domain" : "EXAMPLE.COM",
"managed_hdfs_resource_property_names" : "",
"override_uid" : "true",
"repo_suse_rhel_template" : "[{{repo_id}}]\nname={{repo_id}}\n{% if mirror_list %}mirrorlist={{mirror_list}}{% else %}baseurl={{base_url}}{% endif %}\n\npath=/\nenabled=1\ngpgcheck=0",
"repo_ubuntu_template" : "{{package_type}} {{base_url}} {{components}}",
"security_enabled" : "false",
"smokeuser" : "ambari-qa",
"smokeuser_keytab" : "/etc/security/keytabs/smokeuser.headless.keytab",
"user_group" : "hadoop" }
}
}
}
Step5). Now do a curl PUT on the URL: http://jss1:8080/api/v1/clusters/JoyCluster to push this change to ambari.
curl --user admin:admin -i -H 'X-Requested-By: ambari' -X PUT -d @/tmp/configurations.txt http://jss1:8080/api/v1/clusters/JoyCluster
Step6). Users can validate the changes by accessing the URL:
http://jss1:8080/api/v1/clusters/JoyCluster/configurations?type=cluster-env&tag=version2
.

