Hi all,I’m now to ansible
I have host variable
locked_domains:
and I’m trying to append values to it from task
- set_fact: locked_domains=“{{ locked_domains + item.ID }}”
with_items: “{{ domains.json }}”
Can anyone help?
Hi all,I’m now to ansible
I have host variable
locked_domains:
and I’m trying to append values to it from task
Can anyone help?
I think the short answer is that you don’t. Ansible has a setting that will allow you to merge dictionaries together, but not lists. This setting is global and applies to all dicts. I’m guessing it doesn’t merge lists because there’s no way to indicate if your intent is to merge the list or replace it.
Your best bet, here, is to write a filter_plugin that merges the lists.
e.g.
locked_domains|merge_list(domains.json,'ID')
where merge_list() is a function in a filter_plugin that takes 3 arguments: original_list, new_listofdicts, key.
There might be with_ statement that does this, but looking at your task, I’m not sure if any will do exactly what you want (depends on how you’re going to use locked_domains).
You can try this:
list1|union(list2)
it will output a list with the unique elements from both lists.