Hi Vladimir,
This Solutioñ works.
Thanks for your extended  help on this.
I just tweaked something to match my requirements, overall your solution
works well for me.
Regards
Rakesh

On Thu, 6 Feb 2020, 21:27 Vladimir Botka, <[email protected]> wrote:

> On Thu, 6 Feb 2020 20:37:37 +0530
> Rakesh Parida <[email protected]> wrote:
>
> > > I would like my o/p as below:
> > > dp-steps-common-3.0.12 not equal to
> > > dp-steps-common-3.0.15-1911280809_d103a.noarch
> > > iam-service-default-3.1.37 is equal to
> > > iam-service-default-3.1.37-1911141021_63e48.noarch
> > > iam-python-common-1.0.1 not found in list2
> > >
> > >> > If the numbers of items in list is not equal is there way to
> compare:
> > >> > suppose my lists are:
> > >> >       list1
> > >> >             "dp-steps-common-3.0.12",
> > >> >             "iam-python-common-1.0.1",
> > >> >             "iam-service-default-3.1.37"
> > >> >       list2:
> > >> >             "dp-steps-common-3.0.15-1911280809_d103a.noarch",
> > >> >             "iam-service-default-3.1.37-1911141021_63e48.noarch"
>
> Sure. Transform the data first. For example
>
>     - set_fact:
>         my_pkgs: "{{ my_pkgs|default({})|
>                      combine({pkg_name: {'list1': item, 'list2': pkg2}})
> }}"
>       vars:
>         pkg_name: "{{ item.split('-')[:-1]|join('-') }}"
>         pkg2: "{{ list2|select('search', pkg_name)|list|first|default('')
> }}"
>       loop: "{{ list1 }}"
>     - debug:
>         var: my_pkgs
>
> give
>
>     "my_pkgs": {
>         "dp-steps-common": {
>             "list1": "dp-steps-common-3.0.12",
>             "list2": "dp-steps-common-3.0.15-1911280809_d103a.noarch"
>         },
>         "iam-python-common": {
>             "list1": "iam-python-common-1.0.1",
>             "list2": ""
>         },
>         "iam-service-default": {
>             "list1": "iam-service-default-3.1.37",
>             "list2": "iam-service-default-3.1.37-1911141021_63e48.noarch"
>         }
>     }
>
> Then the manipulation with the data is trivial. For example
>
>     - debug:
>         msg: |
>           {% if item.value.list2 %}
>           {% if item.value.list1 in item.value.list2 %}
>           {{ item.value.list1 }} is equal to {{ item.value.list2 }}
>           {% else %}
>           {{ item.value.list1 }} not equal to {{ item.value.list2 }}
>           {% endif %}
>           {% else %}
>           {{ item.value.list1 }} not found in list2
>           {% endif %}
>       loop: "{{ my_pkgs|dict2items }}"
>
> gives you what you want
>
>     "msg": "iam-python-common-1.0.1 not found in list2\n"
>     "msg": "iam-service-default-3.1.37 is equal to
>     iam-service-default-3.1.37-1911141021_63e48.noarch\n"
>     "msg": "dp-steps-common-3.0.12 not equal to
>     dp-steps-common-3.0.15-1911280809_d103a.noarch\n"
>
> HTH,
>
>         -vlado
>

-- 
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/CAPKxTaD34zAbThAgwtMTHzSshrvWEWh%2BkL-CUtqJXd%3DHV4GY5w%40mail.gmail.com.

Reply via email to