# Set fact based on particular condition of list variable not working

**URL:** <https://forum.ansible.com/t/set-fact-based-on-particular-condition-of-list-variable-not-working/27096>\
**Category:** Ansible Developer\
**Created:** [March 23, 2018, 5:18pm UTC](https://forum.ansible.com/t/set-fact-based-on-particular-condition-of-list-variable-not-working/27096 "2018-03-23T17:18:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohammed\_Yasar\_Aktha](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@Mohammed\_Yasar\_Aktha](https://forum.ansible.com/u/Mohammed_Yasar_Aktha)\
**Post date:** [March 23, 2018, 5:18pm UTC](https://forum.ansible.com/t/set-fact-based-on-particular-condition-of-list-variable-not-working/27096/1 "2018-03-23T17:18:47Z")

</div>

```auto
I have vars file as below

---
builds:
 - 10350.0.0
 - 10351.0.0
 - 10352.0.0
 - 10360.0.0
 - 10361.0.0
 - 10362.0.0
 - 10363.0.0
 - 10364.0.0
 - 10365.0.0
 - 10366.0.0
 - 10367.0.0
 - 10368.0.0
 - 10370.0.0
 - 10371.0.0
 - 10372.0.0
 - 10380.0.0
 - 10381.0.0
 - 10382.0.0
 - 10383.0.0
 - 10384.0.0
 - 10390.0.0
 - 10391.0.0
 - 10392.0.0
 - 10400.0.0
 - 10401.0.0
 - 10402.0.0
 - 10403.0.0
 - 10404.0.0

I am trying to setup an variable when particular build length matches with the package version but it throws with the following error 

    - debug: var=builds[4] -> Getting value from the list works
    - set_fact: buildslen={{ builds | length }} -> Length of the list 
    - debug: var=pkgversion -> Package version
    - debug: var=buildslen 
    - debug: var=builds[{{item}}]
      with_sequence: start=0 count={{ buildslen }} -> Looping through all the versions works fine
    - set_fact: exactlen=builds[{{ item }}]
      when: builds[{{ item }}] == {{ pkgversion }} 
      with_sequence: start=0 count={{ buildslen }}
    - debug: var=exactlen

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [March 23, 2018, 5:52pm UTC](https://forum.ansible.com/t/set-fact-based-on-particular-condition-of-list-variable-not-working/27096/2 "2018-03-23T17:52:27Z")

</div>

You dont need moustaches in conditionals:

when: builds[item] == pkgversion

---

<div class="post-metadata">

**Author:** ![Mohammed\_Yasar\_Aktha](https://avatars.discourse-cdn.com/v4/letter/m/46a35a/32.png) [@Mohammed\_Yasar\_Aktha](https://forum.ansible.com/u/Mohammed_Yasar_Aktha)\
**Post date:** [March 23, 2018, 6:01pm UTC](https://forum.ansible.com/t/set-fact-based-on-particular-condition-of-list-variable-not-working/27096/3 "2018-03-23T18:01:38Z")

</div>

Unfortunately its the same error

fatal: [[abc.xyz.com](http://abc.xyz.com)]: FAILED! =\> {“msg”: "The conditional check ‘builds[item] == pkgversion’ failed. The error was: error while evaluating conditional (builds[item] == pkgversion): ‘list object’ has no attribute u’0’
