On Sat, 29 Jan 2022 05:05:39 -0800 (PST)
John Veliss <[email protected]> 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

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20220131051918.61787990%40gmail.com.

Attachment: pgp3JD_k71DdU.pgp
Description: OpenPGP digital signature

Reply via email to