Look at your quoting here ...
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.
1) You can't have smart quotes. Change to normal double quotes.
2) 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 }}"
Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123
On Jul 14, 2023, at 8:32 AM, Deepak B K <[email protected]> wrote:
Hi Todd,
Please find output below ansible task
- name: Show registered var group_info and vm_name
ansible.builtin.debug:
msg:
- "group_info: {{ group_info }}"
- "vm_name: {{ vm_name }}"
TASK [Show registered var group_info and vm_name]
**************************************************************
ok: [NED-TST1x] => {
"msg": [
"group_info: {'failed': False, 'drs_group_info': {'NED-Cluster':
[{'group_name': 'NED-HOST001-HG', 'hosts': ['ned-host612-hyp'], 'type':
'host'}, {'group_name': 'VM2-on-dev', 'vms': ['deep-test', 'NED-DEV601-X'],
'type': 'vm'}, {'group_name': 'VM2-on-uat', 'vms': ['NED-TST601-X'], 'type':
'vm'}]}, 'changed': False}",
"vm_name: NED-TST601-X"
]
}
Thanks & Regards
Deepak Kumar
On Fri, Jul 14, 2023 at 12:47 PM Deepak B K <[email protected]> wrote:
Hi Groups ,
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: "Gather DRS info about given Cluster"
community.vmware.vmware_drs_group_info:
hostname: "{{ vcenter.hostname }}"
username: "{{ vcenter.username }}"
password: "{{ vcenter.password }}"
validate_certs: "{{ vcenter.validate_certs }}"
cluster_name: "{{ vcenter_env.cluster }}"
delegate_to: localhost
register: group_info
- name: set fact specific group_info VM groups
ansible.builtin.set_fact:
match_vm_group: "{{ item.drs_group_info[vcenter_env.cluster] |
regex_search(vm_name) }}"
when: "{{ item.drs_group_info[vcenter_env.cluster] | regex_search( vm_name
) }}"
loop: "{{ group_info }}"
name: set fact specific VM group
ansible.builtin.set_fact:
vm_groups: “{{ group_info.drs_group_info[vcenter_env.cluster] |
selectattr('type', '==', "vm" ) | list }}”
"vm_groups": "“[{'group_name': VM2-on-dev', 'vms': ['deep-test',
'NED-DEV601-X'], 'type': 'vm'}, {'group_name': 'VM2-on-uat', 'vms':
['NED-TST601-X'], 'type': 'vm'}
}
I appreciate your quick help .
Thanks
Deepak
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/61ff8b55-dd13-4cd2-b718-11eb1fd28cb1n%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAF%3DeWbLmw9m8qg%3DQ0Pu%2BMaajK1H3fmpCxYe-7_-AviOWTNu2sA%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/1587F975-D826-4DAF-8F4F-222E344F16EE%40nist.gov.