Hi ,
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.
my playbook:
- hosts: localhost
tasks:
- name: Create a list1
set_fact:
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-python-common-1.0.1-1910242116.noarch
- iam-service-default-3.1.37-1911141021_63e48.noarch
- name: If the List comparision is equal
debug:
msg: " {{ item[0] }} is equal to {{ item[1] }}"
with_nested:
- "{{ list1 }}"
- "{{ list2 }}"
when: (item[0] in item[1])
- name: If the List comparision is not equal
debug:
msg: " {{ item[0] }} is not equal to {{ item[1] }}"
with_nested:
- "{{ list1 }}"
- "{{ list2 }}"
# when: (item[0] not in item[1])
when: list1 | difference(list2)
o/p:
TASK [If the List comparision is equal]
*****************************************************************************************************************************************************
skipping: [localhost] => (item=[u'dp-steps-common-3.0.12',
u'dp-steps-common-3.0.15-1911280809_d103a.noarch'])
skipping: [localhost] => (item=[u'dp-steps-common-3.0.12',
u'iam-python-common-1.0.1-1910242116.noarch'])
skipping: [localhost] => (item=[u'dp-steps-common-3.0.12',
u'iam-service-default-3.1.37-1911141021_63e48.noarch'])
skipping: [localhost] => (item=[u'iam-python-common-1.0.1',
u'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 equal to
iam-python-common-1.0.1-1910242116.noarch"
}
skipping: [localhost] => (item=[u'iam-python-common-1.0.1',
u'iam-service-default-3.1.37-1911141021_63e48.noarch'])
skipping: [localhost] => (item=[u'iam-service-default-3.1.37',
u'dp-steps-common-3.0.15-1911280809_d103a.noarch'])
skipping: [localhost] => (item=[u'iam-service-default-3.1.37',
u'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 equal to
iam-service-default-3.1.37-1911141021_63e48.noarch"
}
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"
--
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/77d85a73-d16f-44fb-8b17-6223f20b1a62%40googlegroups.com.