--- - name: Get count hosts: localhost connection: local gather_facts: false vars: # Create an anchor for api_info that can be used throughout the file api_info: &api_info # if api_key vars are omitted, INTERSIGHT_API_KEY_ID, INTERSIGHT_API_PRIVATE_KEY, # and INTERSIGHT_API_URI environment variables used for API key data api_private_key: "{{ api_private_key | default(omit) }}" api_key_id: "{{ api_key_id | default(omit) }}" api_uri: "{{ api_uri | default(omit) }}" validate_certs: "{{ validate_certs | default(omit) }}" tasks: # Get a count of the VM hosts - name: "Get VM Count" cisco.intersight.intersight_rest_api: <<: *api_info resource_path: /virtualization/VirtualMachines query_params: $count: true register: resp - name: "Print VM count" ansible.builtin.debug: msg: "VM count {{ resp.count }}"