Hi, I am trying to create an inventory from vmware
This is my partial code on ansible playbook
- name: vm read on VMWARE
hosts: localhost
become: false
gather_facts: true
vars_files:
- secrets.yml
- vars.yml
collections:
- community.vmware
tasks:
- name: Gather all registered virtual machines
vmware_vm_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
show_tag: true
validate_certs: no
delegate_to: localhost
register: vm_info
- name: Filter VMs with tag 'tagtoprocess'
set_fact:
filtered_vms: >-
{{
vm_info.virtual_machines
| selectattr('tags', 'defined')
| selectattr('tags', 'search', 'tagtoprocess')
| list
}}
This is the structure of my vm machines extractions:
"ansible_facts": {
"filtered_vms": [
{
.
.
.
"resource_pool": null,
"tags": [
{
"category_id": "urn:vmomi:InventoryServiceCategory:dfjfjdfjd",
"category_name": "Ansible",
"description": "",
"id": "urn:vmomi:InventoryServiceTag:3ecce703-3dkfkkkfk:GLOBAL",
"name": "tagtoprocess-nosnmp"
},
{
"category_id": "urn:vmomi:InventoryServiceCategory:fc34d73f-4182-432f-b042-1e5f47fc4421:GLOBAL",
"category_name": "Backupp",
"description": "VmSecon",
"id": "urn:vmomi:InventoryServiceTag:6820fb9e-46b1-4eb9-8e6f-e6009ea61f3f:GLOBAL",
"name": "differenttag"
}
],
.
.
.
As you can see, it matches with the tags tagtoprocess-nosnmp but I donāt like this.
How could I change my code matching exactly the machines with tags.name=tagtoprocess?
I think tags.name isnāt right
How could I solve?
Thanks a lot for your help