Bumping the version of a library and deleting older versions

I have a jar file named something like myjar -1.1.0-assembly.jar. When our team does a release, a new jar named something like myjar -1.2.0-assembly.jar is created and needs to be deployed to the world. Additionally, any jars matching the myjar -[VERSION]-assembly.jar pattern need to be deleted as part of this process to prevent any class conflicts at runtime.

What’s the best way to do this with Ansible?

Package them and let your distribution’s package manager handle that?

packaging is better, but a quick and dirty play:

- shell: ls myjar -*-assembly.jar
  register: existingjars

- copy: newjar dest=
   register: jarchanged

# or this can also be a handler, change register:jarchanged to notify
- file: path={{item}} state=absent
   with_items: existingjars
   when: jarchanged.changed