I can't reuse the content of a variable for two different parameters. (host_groups and tags). (Documentation here)
I have a variable in this form :
probe:
- name: prob1
groups:
- group1
- group2
- name: prob2
groups:
- group1
- group3
Then, I have a task that loops for each probes that works well.
- name: Probe
community.zabbix.zabbix_host:
host_name: "{{ item.name }}"
host_groups: "{{ item.groups }}"
loop: "{{ zabbix_sensor }}"
But I would like to add the values I have in the groups variable in the tags parameter of my task.
- name: Probe
community.zabbix.zabbix_host:
host_name: "{{ item.name }}"
host_groups: "{{ item.groups }}"
tags: "{{ item.groups }}"
loop: "{{ zabbix_sensor }}"
This doesn't work because it expects the key in the following format - tag: {{value}}.
I don't want to create another tag variable containing the same values as groups because the values will be identical.
The result for this to work would be something like :
- name: Probe
community.zabbix.zabbix_host:
host_name: probe1
host_groups: ['group1','group2']
tags:
- tag: group1
- tag: group2
Any idea how to get there?
I've tried a lot of things, but I can't get my result
Use the filter community.general.dict_kv to create the dictionary. For example, given the list
declare the dictionary
gives
Example of a complete playbook for testing
gives (abridged)
Q: "Have a tag with name and value."
A: Concatenate the lists
gives
Q: "For groups, I don't need a value, but in some cases I do."
A: In the example below, any list will be converted to tags only and any other type, expecting a hash, will be converted to the tag and value
gives (abridged)