Skip to main content
akhilsnaik
Gold ⭐️⭐️⭐️
Gold ⭐️⭐️⭐️
Dec 21, 2018 2:09 AM UTC

Remove Old Stack Versions script doesnt work in ambari-2.7.+ versions

  • Oct 5, 2026 8:55 AM UTC
  • 3 replies
  • 4987 views
  • Translate All

Disclaimer: This article is based on my personal experience and knowledge. Don't take it as a standard guidelines, understand the concept and modify it for your environmental best practices and use case.

Ambari unofficially supports a curl command which will help deleting the old stacks and packages from each of the host .

the script is described in https://issues.apache.org/jira/browse/AMBARI-18435 and also in the article : https://community.hortonworks.com/articles/202904/how-to-remove-all-previous-version-hdp-directories.html

But this above script doesn't work in ambari-2.7.3 version.

Root cause : the script will fail with below exception :

Traceback (most recent call last):
File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 119, in <module>
RemovePreviousStacks().execute()
File "/usr/lib/ambari-agent/lib/resource_management/libraries/script/script.py", line 352, in execute
method(env)
File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 49, in actionexecute
self.remove_stack_version(structured_output, low_version)
File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 54, in remove_stack_version
packages_to_remove = self.get_packages_to_remove(version)
File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 77, in get_packages_to_remove
all_installed_packages = self.pkg_provider.all_installed_packages()
AttributeError: 'YumManager' object has no attribute 'all_installed_packages'

this was due to fix of : https://issues.apache.org/jira/browse/AMBARI-21738 ( https://github.com/apache/ambari/commit/e7c4ed761072256dabd881242a0eea40d94cf8af) the fix is not handled properly in remove_previous_stacks.py

Workaround :

1) go to each ambari-agent node and edit the file remove_previous_stacks.py

[root@asn1 current]#vi /var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py

2) go to line : 77

edit the line from :

all_installed_packages = self.pkg_provider.all_installed_packages()

to

all_installed_packages = self.pkg_provider.installed_packages()

3) retry the operation via curl again

ex:

curl 'http://asn1.openstacklocal:8080/api/v1/clusters/asnaik/requests' -u admin:admin -H "X-Requested-By: ambari" -X POST -d'{"RequestInfo":{"context":"remove_previous_stacks", "action" : "remove_previous_stacks", "parameters" : {"version":"3.0.1.1-84"}}, "Requests/resource_filters": [{"hosts":"asn1.openstacklocal"}]}'

The Operation has to be success now. If you are facing any issue please comment in this thread and tag me

Please upvote this article if you find this helpful

3 replies

shubh_luck_
Silver ⭐️⭐️
Dec 22, 2018 8:08 PM UTC

Thanks Akhil

Translate
massoudm
Silver ⭐️⭐️
Jan 27, 2019 11:43 PM UTC

In my case, I get a different error:

Traceback (most recent call last):
File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 119, in <module>
RemovePreviousStacks().execute()
File "/usr/lib/ambari-agent/lib/resource_management/libraries/script/script.py", line 352, in execute
method(env)
File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 49, in actionexecute
self.remove_stack_version(structured_output, low_version)
File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 53, in remove_stack_version
self.check_no_symlink_to_version(structured_output, version)
File "/var/lib/ambari-agent/cache/custom_actions/scripts/remove_previous_stacks.py", line 94, in check_no_symlink_to_version
raise Fail("{0} contains symlink to version for remove! {1}".format(stack_root_current, version))
resource_management.core.exceptions.Fail: /usr/hdp/current/ contains symlink to version for remove! 3.0.1.0-187

Do you have any solution for this error?

Translate
Stephbat
Gold ⭐️
Jul 29, 2020 1:34 PM UTC

@massoudm Did you found a solution ? I get the same error after the upgrade of HDP 3.1.0 to 3.1.4

Thanks in advance

Translate