I am trying to parse the list variable but I am getting ansible unsafe text I need to match the vm name and get the corresponding vm group from the registered variable vm_groups.
tasks:
name: set fact specific VM group
ansible.builtin.set_fact:
vm_groups: “{{ group_info.drs_group_info[vcenter_env.cluster] | selectattr(‘type’, ‘==’, “vm” ) | list }}”
- name: Show registered var group_info and vm_name
ansible.builtin.debug:
msg:
- "group_info: {{ group_info }}"
- "vm_name: {{ vm_name }}"
It would be helpful to include the job log for the relevant section of your playbook as well. You say you are trying to parse “the list variable” but you don’t say what that variable is or show what it contains. Please help us help you.
name: set fact specific VM group
ansible.builtin.set_fact:
vm_groups: “{{ group_info.drs_group_info[vcenter_env.cluster] | selectattr(‘type’, ‘==’, “vm” ) | list }}”
That first and last quote are a “smart quotes” (leaning quotes). Your quotes around “vm” are double quotes.
You can’t have smart quotes. Change to normal double quotes.
You can’t have double quotes inside double quotes. Change “vm” to ‘vm’.
name: set fact specific VM group
ansible.builtin.set_fact:
vm_groups: “{{ group_info.drs_group_info[vcenter_env.cluster] | selectattr(‘type’, ‘==’, ‘vm’ ) | list }}”