nutanix / nutanix.ansible

Official Nutanix Ansible collections
GNU General Public License v3.0
64 stars 35 forks source link

[Bug] custom_filter ineffective in module nutanix.ncp.ntnx_foundation_central_imaged_nodes_info #374

Open nx-sbourdeaud opened 1 year ago

nx-sbourdeaud commented 1 year ago

Describe the bug Using custom_filter has not effect on the result/output (all imaged nodes are displayed)

To Reproduce Steps to reproduce the behavior:

  1. ansible-playbook imaged_nodes_info.yml
  2. sample playbook used:

    ---
    - name: Imaged Nodes Playbook
    hosts: localhost
    gather_facts: false
    collections:
    - nutanix.ncp
    
    tasks:
    - name: Imaged-Node details with custom filter
    ntnx_foundation_central_imaged_nodes_info:
      nutanix_host: "{{ pc_ip }}"
      nutanix_username: "{{ vault_pc_username }}"
      nutanix_password: "{{ vault_pc_password }}"
      validate_certs: false
      custom_filter:
        block_serial: "22SG6M450006"
    register: output
    
    - name: details of imaged node 
    debug:
      msg: '{{ output }}'

Expected behavior Only nodes whose properties match the custom filter should be returned.

bhati-pradeep commented 1 year ago

@abhimutant Please check this, thanks.

bhati-pradeep commented 9 months ago

Moving it to 1.9.2 due to unavailability of fix. Reminder: @abhimutant please can you check this, thanks

mdhowle commented 4 months ago

I'm seeing a similar issue with ntnx_clusters_info and ntnx_hosts_info with both filter and custom_filter. Is this related?

Setting a filter name: "{{ cluster_name }}" with the ntnx_clusters_info module retrieves all clusters. Similarly, with ntnx_hosts_info, setting a filter cluster_name: "{{ cluster_name }}" retrieves all hosts.

ntnx_vms_info, however, filters correctly with cluster_name: "{{ cluster_name }}".

For example, this returns all clusters

---
[...]
  tasks:
    - name: Get cluster info
      nutanix.ncp.ntnx_clusters_info:
        nutanix_host: "{{ prism_host }}"
        nutanix_username: "{{ prism_username }}"
        nutanix_password: "{{ prism_password }}"
        filter:
          name: "{{ cluster_name }}"
      register: cluster_info

The work around I have is

    - name: Get cluster info
      nutanix.ncp.ntnx_clusters_info:
        nutanix_host: "{{ prism_host }}"
        nutanix_username: "{{ prism_username }}"
        nutanix_password: "{{ prism_password }}"
        filter:
          name: "{{ cluster_name }}"  # DOES NOT WORK
      register: all_clusters

   - name: Get cluster
      set_fact:
        cluster: "{{ (all_clusters.response.entities | selectattr('status.name', '==', cluster_name ) | first) }}"

    - name: Get hosts
      nutanix.ncp.ntnx_hosts_info:
        nutanix_host: "{{ prism_host }}"
        nutanix_username: "{{ prism_username }}"
        nutanix_password: "{{ prism_password }}"
        filter:
          cluster_name: "{{ cluster_name }}"  # DOES NOT WORK
      register: all_hosts

    - name: Get hosts info
      set_fact:
        hosts: "{{ all_hosts.response.entities | selectattr('status.cluster_reference.uuid', '==', cluster.metadata.uuid ) }}"