[ansible-project ] getting unsafe ansible text when I trying to parse ansible register variable

626 views
Skip to first unread message

Deepak B K

unread,
Jul 14, 2023, 3:17:48 AM7/14/23
to Ansible Project

Todd Lewis

unread,
Jul 14, 2023, 6:50:39 AM7/14/23
to ansible...@googlegroups.com, uto...@gmail.com
Please show us "group_info" and "vm_name":
- 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.

Rowe, Walter P. (Fed)

unread,
Jul 14, 2023, 7:14:32 AM7/14/23
to ansible...@googlegroups.com
Adding to Todd's request for more details .. also look at json_query vs selectattr if you are just filtering a JSON list on attribute value.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/08b16ee1-1087-4b0a-21f7-be65df5dc199%40gmail.com.

Deepak B K

unread,
Jul 14, 2023, 8:34:13 AM7/14/23
to ansible...@googlegroups.com
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

--
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 ansible-proje...@googlegroups.com.

Rowe, Walter P. (Fed)

unread,
Jul 14, 2023, 9:11:17 AM7/14/23
to 'Rowe, Walter P. (Fed)' via Ansible Project
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

Deepak B K

unread,
Jul 17, 2023, 6:59:47 AM7/17/23
to ansible...@googlegroups.com
Dear Walter, 

Thank you very much for the timely help. I am all set with getting the correct group name out of the drs information .

Thanks 
Deepak Kumar

Reply all
Reply to author
Forward
0 new messages