I want to compare two lists . But while doing this the list1 item loops over each item of list2. I just want item of list 1 just to compare between matching item in list2 and not with others.
TASK [If the List comparision is not equal] *************************************************************************************************************************************************
ok: [localhost] => (item=[u’dp-steps-common-3.0.12’, u’dp-steps-common-3.0.15-1911280809_d103a.noarch’]) => {
“msg”: " dp-steps-common-3.0.12 is not equal to dp-steps-common-3.0.15-1911280809_d103a.noarch"
}
ok: [localhost] => (item=[u’dp-steps-common-3.0.12’, u’iam-python-common-1.0.1-1910242116.noarch’]) => {
“msg”: " dp-steps-common-3.0.12 is not equal to iam-python-common-1.0.1-1910242116.noarch"
}
ok: [localhost] => (item=[u’dp-steps-common-3.0.12’, u’iam-service-default-3.1.37-1911141021_63e48.noarch’]) => {
“msg”: " dp-steps-common-3.0.12 is not equal to iam-service-default-3.1.37-1911141021_63e48.noarch"
}
ok: [localhost] => (item=[u’iam-python-common-1.0.1’, u’dp-steps-common-3.0.15-1911280809_d103a.noarch’]) => {
“msg”: " iam-python-common-1.0.1 is not equal to dp-steps-common-3.0.15-1911280809_d103a.noarch"
}
ok: [localhost] => (item=[u’iam-python-common-1.0.1’, u’iam-python-common-1.0.1-1910242116.noarch’]) => {
“msg”: " iam-python-common-1.0.1 is not equal to iam-python-common-1.0.1-1910242116.noarch"
}
ok: [localhost] => (item=[u’iam-python-common-1.0.1’, u’iam-service-default-3.1.37-1911141021_63e48.noarch’]) => {
“msg”: " iam-python-common-1.0.1 is not equal to iam-service-default-3.1.37-1911141021_63e48.noarch"
}
ok: [localhost] => (item=[u’iam-service-default-3.1.37’, u’dp-steps-common-3.0.15-1911280809_d103a.noarch’]) => {
“msg”: " iam-service-default-3.1.37 is not equal to dp-steps-common-3.0.15-1911280809_d103a.noarch"
}
ok: [localhost] => (item=[u’iam-service-default-3.1.37’, u’iam-python-common-1.0.1-1910242116.noarch’]) => {
“msg”: " iam-service-default-3.1.37 is not equal to iam-python-common-1.0.1-1910242116.noarch"
}
ok: [localhost] => (item=[u’iam-service-default-3.1.37’, u’iam-service-default-3.1.37-1911141021_63e48.noarch’]) => {
“msg”: " iam-service-default-3.1.37 is not equal to iam-service-default-3.1.37-1911141021_63e48.noarch"
}
Desired o/p of last task:
ok: [localhost] => (item=[u’dp-steps-common-3.0.12’, u’dp-steps-common-3.0.15-1911280809_d103a.noarch’]) => {
“msg”: " dp-steps-common-3.0.12 is not equal to dp-steps-common-3.0.15-1911280809_d103a.noarch"
Actually this is not what i want , i just want my item1 to not to iterate over the loop and compare every item, it should only compare the relative item2.
PLs check my o/p.
I just only want the o/p:
“msg”: " dp-steps-common-3.0.12 is not equal to dp-steps-common-3.0.15-1911280809_d103a.noarch"
- debug:
msg: "{{ item.0 }} is not equal to {{ item.1 }}"
loop: "{{ list1|zip(list2)|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"
The order and the format of the items is significant. HTH,
- 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"
name: If the List comparision is not equal
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])
As you can see the items are not same in both list.
In my template files I have to pass it as variables .Can you help me for supervisor.slots.ports as I have done for the remaining but unable to do that
I have tried several times but failed
You already are engaged in a conversation on this list. Branching that into another by verbatim forwarding a single message without context isn’t going to help you get better responses.
Please post proper questions, or just wait until the volunteers here respond to your original question.
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"
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