Hey, tried both in 2.2.0 and they work for me

---
#
- hosts: localhost
  connection: local
  gather_facts: no


  vars:


    instance_ids:
      - "i-bae34407"
      - "i-d2e4436f"


    excluded_ids:
      - "i-bae34407"


  tasks:


    - debug: var=excluded_ids


    - debug: var=instance_ids


    - set_fact: instance_ids1="{% for item in instance_ids %}{% if item not 
in excluded_ids %}{{ item }}{% endif %}{% endfor %}"


    - debug: var=instance_ids1

Result
 [WARNING]: provided hosts list is empty, only localhost is available




PLAY [localhost] 
***************************************************************


TASK [debug] 
*******************************************************************
ok: [localhost] => {
    "excluded_ids": [
        "i-bae34407"
    ]
}


TASK [debug] 
*******************************************************************
ok: [localhost] => {
    "instance_ids": [
        "i-bae34407",
        "i-d2e4436f"
    ]
}


TASK [set_fact] 
****************************************************************
ok: [localhost]


TASK [debug] 
*******************************************************************
ok: [localhost] => {
    "instance_ids1": "i-d2e4436f"
}


PLAY RECAP 
*********************************************************************
localhost                  : ok=4    changed=0    unreachable=0    failed=0


---
#
- hosts: localhost
  connection: local
  gather_facts: no


  vars:


    instance_ids:
      - "i-bae34407"
      - "i-d2e4436f"


    excluded_ids:
      - "i-bae34407"


  tasks:


    - debug: var=excluded_ids


    - debug: var=instance_ids


    - set_fact: instance_ids1="{{ instance_ids  | difference(excluded_ids) 
}}"


    - debug: var=instance_ids1


Result

 [WARNING]: provided hosts list is empty, only localhost is available




PLAY [localhost] 
***************************************************************


TASK [debug] 
*******************************************************************
ok: [localhost] => {
    "excluded_ids": [
        "i-bae34407"
    ]
}


TASK [debug] 
*******************************************************************
ok: [localhost] => {
    "instance_ids": [
        "i-bae34407",
        "i-d2e4436f"
    ]
}


TASK [set_fact] 
****************************************************************
ok: [localhost]


TASK [debug] 
*******************************************************************
ok: [localhost] => {
    "instance_ids1": [
        "i-d2e4436f"
    ]
}


PLAY RECAP 
*********************************************************************
localhost                  : ok=4    changed=0    unreachable=0    failed=0


On Wednesday, July 6, 2016 at 7:38:42 PM UTC+5:30, Cos Bug wrote:
>
> Thanks Aneesh,
>
> The first suggestion brings this:
>
> TASK: [Exclude them from instance_ids] ****************************
> ok: [127.0.0.1] => {"ansible_facts": {"instance_ids1": "set([u' ', u'd', 
> u'f', u',', u'2', u'u', u'6'])"}}
>
>
> TASK: [debug var=instance_ids1] ***********************************
> ok: [127.0.0.1] => {
>     "var": {
>         "instance_ids1": "set([u' ', u'd', u'f', u',', u'2', u'u', u'6'])"
>     }
> }
>
> the second one doesn't work either (already tried before posting this :-) 
> ).
>
> Tested with Ansible version 1.9.4 & 2.2.0
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/494220ff-110b-453c-8210-d4bca6325806%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to