Skip to content

Fix uninstall to be idempotent#71

Open
alyssaruth wants to merge 1 commit intoComcast:masterfrom
alyssaruth:master
Open

Fix uninstall to be idempotent#71
alyssaruth wants to merge 1 commit intoComcast:masterfrom
alyssaruth:master

Conversation

@alyssaruth
Copy link

@alyssaruth alyssaruth commented Jun 4, 2025

I was playing with the uninstall and noticed it explodes if you re-run a second time and the package isn't there:

TASK [comcast.sdkman : Uninstall SDK candidates/versions] ************************************************************************************************************************************
failed: [localhost] (item={'candidate': 'java', 'version': '17.0.11-tem'}) => {"ansible_loop_var": "item", "changed": true, "cmd": ". /home/alyssa/.sdkman/bin/sdkman-init.sh && sdk uninstall java 17.0.11-tem", "delta": "0:00:00.628336", "end": "2025-06-04 16:14:44.773058", "item": {"candidate": "java", "version": "17.0.11-tem"}, "msg": "non-zero return code", "rc": 1, "start": "2025-06-04 16:14:44.144722", "stderr": "java 17.0.11-tem is not installed on your system", "stderr_lines": ["java 17.0.11-tem is not installed on your system"], "stdout": "", "stdout_lines": []}

Fix is basically the same as in #51 - I also made the check a bit less specific since it looks like it's already changed once (mine says "not installed on your system" rather than "not installed.")

Testing

Happy to add automated tests if that's relatively doable, I'm fairly new to ansible so not sure where to start with that atm. But I've tested it manually with the following steps.

  1. Install two versions of ant with the following config:
  - role: comcast.sdkman
    tags: ant-test
    sdkman_install_packages:
      - { candidate: ant, version: "1.9.7" }
      - { candidate: ant, version: "1.10.14" }
  1. Update the config to uninstall one of them:
  - role: comcast.sdkman
    tags: ant-test
    sdkman_install_packages:
      - { candidate: ant, version: "1.10.14" }
    sdkman_uninstall_packages:
      - { candidate: ant, version: "1.9.7" }

It's removed and correctly identified as changed:

TASK [comcast.sdkman : Install SDK candidates/versions] ********************************************************************************************************************************
ok: [localhost] => (item={'candidate': 'ant', 'version': '1.10.14'})

TASK [comcast.sdkman : Uninstall SDK candidates/versions] ******************************************************************************************************************************
changed: [localhost] => (item={'candidate': 'ant', 'version': '1.9.7'})
  1. Run again with no changes to config, there's no error and check shows as "ok" (not changed):
TASK [comcast.sdkman : Install SDK candidates/versions] ********************************************************************************************************************************
ok: [localhost] => (item={'candidate': 'ant', 'version': '1.10.14'})

TASK [comcast.sdkman : Uninstall SDK candidates/versions] ******************************************************************************************************************************
ok: [localhost] => (item={'candidate': 'ant', 'version': '1.9.7'})

@CLAassistant
Copy link

CLAassistant commented Jun 4, 2025

CLA assistant check
All committers have signed the CLA.

@alyssaruth alyssaruth marked this pull request as ready for review June 4, 2025 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments