On Fri, 16 Oct 2020 09:13:21 -0700 (PDT) jean-christophe manciot <[email protected]> wrote:
> - debug:
> msg: "{{ item.workstations|
> selectattr('name', 'eq', os_name)|
> selectattr('revision', 'eq', os_revision)|
> map(attribute= 'url')|
> list }}"
> loop: "{{ domain_definition }}"
> when: item.workstations|length > 0
> vars:
> os_name: ubuntu1
> os_revision: '2017-08-16'
>
> Isn't there a loopless solution?
Next option is a custom filter. For example,
shell> cat filter_plugins/custom_select_url.py
def custom_select_url(l, os_name, os_revision):
l1 = []
for i in l:
if 'workstations' in i.keys():
for j in i['workstations']:
if (j['name'] == os_name) and \
(j['revision'] == os_revision):
l1.append(j['url'])
return l1
class FilterModule(object):
def filters(self):
return {
'custom_select_url': custom_select_url
}
and the playbook
shell> cat pb.yml
- hosts: localhost
tasks:
- include_vars: domain_definition.yml
- debug:
msg: "{{ domain_definition|
custom_select_url('ubuntu1', '2017-08-16') }}"
give
msg:
- http://ubuntu1.example.com:9912/2017-08-16
--
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/20201016213159.7d855b65%40gmail.com.
pgpsmX2Qsz4Oi.pgp
Description: OpenPGP digital signature
