In a previous post we saw how to automate installation of different versions of ParaView and give each one its own icon and menu entry.
What if we want to add a new version without re-downloading all the previous ones ?
We need to:
- Find which versions we already have
- Store this information
- Skip steps for the ones we have
Although, these sound obvious it took quite some time to find the proper way to do it in ansible, hence this note.
---
- name: ParaView releases
hosts: localhost
#become: no
vars:
opt: "{{ ansible_env.HOME }}/opt"
paraview:
- file: "ParaView-5.13.3-MPI-Linux-Python3.10-x86_64.tar.gz"
base_version: "5.13"
version: "5.13.3"
checksum: "sha256:2fd7cb3e1155576e3ed56a4a238bdf1b523b7e85611b90f4437c66fb2908ddc8"
exists: false #NEW: add a field to record whether we have this versions or not
...
tasks:
...
- name: Check which versions we are missing
stat:
path: "{{ installation_paths[item.version] }}/bin/paraview"
loop: "{{ paraview }}"
register: paraview_path_stat
- name: update facts
block:
- name: update facts 1/2
ansible.utils.update_fact:
updates:
- path: "paraview[{{item}}].exists"
value: "{{paraview_path_stat.results[item].stat.exists}}"
loop: "{{ range(paraview|length) }}"
register: updated
- name: update facts 2/2
ansible.builtin.set_fact:
paraview: "{{updated.results[-1].paraview}}" # updated.results
# contains an item for each iteration of the loop above. Since by the
# time we run the last we have updated all of them we keep the last one.
- name: Download ParaView Binaries
...
when: not item.exists # All subsequent steps are executed only if we are missing this specific version.
# There is probably a way to make this better :-)