On Thu, 30 Jan 2020 20:20:53 -0800 (PST)
Pawan Kumar <[email protected]> wrote:

> > > 
> > >         list1: 
> > >           - iam-python-common-1.0.0 
> > >           - iam-service-default-3.1.42 
> > >           - dp-steps-common-3.0.12 
> > >         list2: 
> > >           - dp-steps-common-3.0.15-1911280809_d103a.noarch 
> > >           - iam-service-default-3.1.37-1911141021_63e48.noarch 
> > >           - iam-python-common-1.0.1-1910242116.noarch   

> >
> >      - debug: 
> >          msg: "{{ item.0 }} is not equal to {{ item.1 }}" 
> >        loop: "{{ list1|sort|zip(list2|sort)|list }}" 
> >        when: item.0.split('-')[-1] is not version(item.1.split('-')[-2]) 
> >
> > gives 
> >
> >     "msg": "dp-steps-common-3.0.12 is not equal to 
> >     dp-steps-common-3.0.15-1911280809_d103a.noarch" 
> >     "msg": "iam-python-common-1.0.0 is not equal to 
> >     iam-python-common-1.0.1-1910242116.noarch" 
> >     "msg": "iam-service-default-3.1.42 is not equal to 
> >     iam-service-default-3.1.37-1911141021_63e48.noarch" 

> Just for curiosity , would be please explain the steps in solution. 

Sure. The steps are self-explaining, I think.

1) See "zip"
https://docs.ansible.com/ansible/devel/user_guide/playbooks_filters.html#combining-items-from-multiple-lists-zip-and-zip-longest

     - debug:
         msg: "{{ item.0 }}
               {{ item.1 }}"
       loop: "{{ list1|sort|zip(list2|sort)|list }}"

gives

    "msg": "dp-steps-common-3.0.12 
dp-steps-common-3.0.15-1911280809_d103a.noarch"
    "msg": "iam-python-common-1.0.0 iam-python-common-1.0.1-1910242116.noarch"
    "msg": "iam-service-default-3.1.42 
iam-service-default-3.1.37-1911141021_63e48.noarch"


2) See "split" and "Common Sequence Operations"
https://docs.python.org/3/library/stdtypes.html?highlight=split#str.split
https://docs.python.org/3/library/stdtypes.html?highlight=split#common-sequence-operations

     - debug:
         msg: "{{ item.0.split('-')[-1] }}
               {{ item.1.split('-')[-2] }}"
       loop: "{{ list1|sort|zip(list2|sort)|list }}"

gives

    "msg": "3.0.12 3.0.15"
    "msg": "1.0.0 1.0.1"
    "msg": "3.1.42 3.1.37"


3) See "Version Comparison"
https://docs.ansible.com/ansible/latest/user_guide/playbooks_tests.html#version-comparison

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/20200131092004.54054cb4%40gmail.com.

Attachment: pgp6p5rXtmlWB.pgp
Description: OpenPGP digital signature

Reply via email to