On Sat, 29 Jan 2022 05:05:39 -0800 (PST)
John Veliss <
vel...@gmail.com> wrote:
> I would like to include some ansible *"when"* conditions based on if a
> software package is greater than a value ...
Set default to 'undef' if the package is missing, e.g.
- package_facts:
- set_fact:
_version: "{{ ansible_facts.packages[my_pkg].0.version|
default('undef') }}"
- set_fact:
found: "{{ my_pkg in ansible_facts.packages and
_version is version(my_version, '>') }}"
- debug:
msg: "{{ my_pkg }}: {{ _version }}"
when: found
- debug:
msg: "{{ my_pkg }} NOT found"
when: not found
Then if the package is installed you get, e.g.
> ansible-playbook test.yml -e my_pkg=yamllint -e my_version=1.20
msg: 'yamllint: 1.20.0-1'
If the package is not installed you get, e.g.
> ansible-playbook test.yml -e my_pkg=yamllintXY -e my_version=1.20
msg: yamllintXY NOT found
If the package is installed but the version is lower you get, e.g.
> ansible-playbook test.yml -e my_pkg=yamllint -e my_version=1.21
msg: yamllint NOT found
--
Vladimir Botka