Hi All,
I’m using a Jinja2 expression to exclude form one list the elements present in another list but it doesn’t work as expected.
Here is an extract from a larger playbook which captures the input and out put before and after ‘set_fact’ statement:
`
-
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_ids1
`
and here the strange output of instance_ids1 variable:
`
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: [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”
}
}
`
As you can see I get some rubbish in instance_ids1.
But if I run a separate playbook defined like this:
`