#print na_ontap_rest_info output to file for multiple hosts

1 messages · Page 1 of 1 (latest)

stoic sage
#

I need to pull some information from a large number of ONTAP clusters and store the info into a separete file per cluster. This info will then be importing into mongoDB and used for various reporting requirements.

I have the playbook setup using a loop for the login credentials so it can iterate over each cluster defined in a file but the "results" are all stored in a single variable so when copying to a file i send up with all output together.

Is there a better way to do this or how can i register the results for each item in the loop separately?

  collections:
    - netapp.ontap
  gather_facts: false
  tasks:
    - name: gather ontap info required for esa select subsets only
      netapp.ontap.na_ontap_rest_info:
        hostname: "{{ item.cluster_ip }}" 
        username: "{{ item.username }}"
        password: "{{ item.password }}" 
        https: true
        validate_certs: false
        use_rest: Always
        use_python_keys: true
        hal_linking: false
        max_records: 5000
        fields:
          - '*'
        gather_subset:
          - cluster
          - cluster/nodes
          - storage/aggregates
          - storage/shelves
          - storage/switches
      register: "{{ ontap_info }}"
      loop: "{{ clusters }}"     

    - name: copy output to a file
      ansible.builtin.copy:
        content: "{{ ontap_info }}"
        dest: /playbooks/esa/inventory/"{{ cluster + uuid }}"```
atomic niche
#

You can loop over the result and extract the cluster-specific information from the global object.

- name: copy output to a file ansible.builtin.copy: content: "{{ item.ontap_info.records }}" dest: /playbooks/esa/inventory/"{{ item.item + uuid }}" loop: "{{ ontap_info.results }}" loop_control: label: "{{ item.item }}"