Laci, On Thu, 13 Aug 2020 08:47:31 -0700 (PDT) Laci <[email protected]> wrote:
> ... it finds the package only if no specific version is
> specified. For example it will find nginx and send email but won't
> find nginx-1.12.2
Try this. Loop "with_together" lists of packages' names and versions.
In the task's vars create list of the versions "pkgv". The
attribute "version" of the dictionary "ansible_facts.packages" is a
list because there may be more versions installed. In the condition
"when" test the searched version "item.1" is in the list "pkgv".
vars:
- pkg_list:
- nginx-1.12.2
- zip-3.0
tasks:
- package_facts:
- debug:
msg: "Found {{ item.0 }}-{{ item.1 }}"
with_together:
- "{{ pkg_list|
map('regex_replace','^(.*)-(.*)$', '\\1')|list }}"
- "{{ pkg_list|
map('regex_replace','^(.*)-(.*)$', '\\2')|list }}"
when: pkgv|map('regex_search', '^' ~ item.1)|list|length > 0
vars:
pkgn: "{{ ansible_facts.packages[item.0]|default([]) }}"
pkgv: "{{ pkgn|map(attribute='version')|list }}"
Fit the condition to your needs. It's trivial to create a list of
found packages in the loop test it and send an email.
--
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/20200813194648.2dcdcc85%40gmail.com.
pgpaDy7Z2HfUO.pgp
Description: OpenPGP digital signature
