- debug: var=excluded_ids
- debug: var=instance_ids
- name: Exclude them from instance_ids
set_fact: instance_ids1="{% for item in instance_ids if item not in excluded_ids %}{{ item }}{% endfor %}"
- debug: var=instance_ids1TASK: [debug var=excluded_ids] ************************************
ok: [127.0.0.1] => {
"var": {
"excluded_ids": [
"i-bae34407"
]
}
}
TASK: [debug var=instance_ids] ************************************
ok: [127.0.0.1] => {
"var": {
"instance_ids": [
"i-bae34407",
"i-d2e4436f"
]
}
}
TASK: [Exclude them from instance_ids] ****************************
ok: [127.0.0.1] => {"ansible_facts": {"instance_ids1": "u, ud26f"}}
TASK: [debug var=instance_ids1] ***********************************
ok: [127.0.0.1] => {
"var": {
"instance_ids1": "u, ud26f"
}
}---
#
- 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 }}{% endfor %}"
- debug: var=instance_ids1
TASK: [debug var=excluded_ids] ************************************************
ok: [127.0.0.1] => {
"var": {
"excluded_ids": [
"i-bae34407"
]
}
}
TASK: [debug var=instance_ids] ************************************************
ok: [127.0.0.1] => {
"var": {
"instance_ids": [
"i-bae34407",
"i-d2e4436f"
]
}
}
TASK: [set_fact instance_ids1="{% for item in instance_ids if item not in excluded_ids %}{{ item }}{% endfor %}"] ***
ok: [127.0.0.1] => {"ansible_facts": {"instance_ids1": "i-d2e4436f"}}
TASK: [debug var=instance_ids1] ***********************************************
ok: [127.0.0.1] => {
"var": {
"instance_ids1": "i-d2e4436f"
}
}
set_fact: instance_ids1="{{ instance_ids | difference(excluded_ids) }}"set_fact: instance_ids1="{% for item in instance_ids %}{% if item not in excluded_ids %}{{ item }}{% endif %}{% endfor %}"
Hi All,Enter code here...
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'])"
}
}
---
#
- 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 [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 [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