Hi Vladimir Botka,

I could not opened attachment, Please confirm if you updated anything to
the file.

On Sun, Sep 11, 2022 at 3:18 PM Aharonu <[email protected]> wrote:

> ++ looping tem. Missed to loop team.
>
> On Sun, Sep 11, 2022 at 2:48 PM Aharonu <[email protected]> wrote:
>
>> What I understood from Clustes.csv file is, it is pring first volume
>> names and then status. Example like
>> Clusters,192,168.0.1,volume1,volume2,volume3,online,online,online
>> Clusters,192,168.0.2,volume7,volume8,volume9,online,online,online
>>
>>
>> On Sun, Sep 11, 2022 at 2:42 PM Aharonu <[email protected]> wrote:
>>
>>> Hi,
>>>
>>> Sorry for delay in response.
>>>
>>> Per your suggestion i have  update my playbook but it seems still
>>> something is missing. Could you please take a look once. Thank you.
>>>
>>> Playbook:
>>> ---
>>> - name: Ontap REST API
>>>   hosts: localhost
>>>   gather_facts: false
>>>   collections:
>>>     - netapp.ontap
>>>   vars_files:
>>>      - /home/u630850/facts/var_file.yml
>>>      - /home/u630850/facts/admin_clusters.yml
>>>
>>> *vars:    csv_query: '[].[`Clusters`, key, value[].**volume**, value[].*
>>> *state*
>>> *]'    csv: "{{ Clusters|dict2items|json_query(csv_query)|
>>> map('flatten')|map('join', ',')|list }}"*
>>>     login: &login
>>>       #hostname: "{{ admin_ip }}"
>>>       username: "{{ admin_username }}"
>>>       password: "{{ admin_password }}"
>>>       https: true
>>>       validate_certs: false
>>>       feature_flags:
>>>         trace_apis: true
>>>   tasks:
>>>     - name: run ontap REST API command as cluster admin - get version
>>>       netapp.ontap.na_ontap_rest_cli:
>>>         use_rest: Always
>>>         hostname: "{{ item }}"
>>>         #use_python_keys: true
>>>         <<: *login
>>>         command: 'volume'
>>>         verb: 'GET'
>>>         params: {'volume': '*','state': 'online'}
>>>       register: ontap
>>>       loop: "{{ admin_clusters }}"
>>>       *loop_control:*
>>>         label: "{{ item }}"
>>>     - set_fact:
>>>         Clusters: "{{  Clusters  |default({}) | combine( {item.item:
>>> item |* json_query(get_attrs)*}) }}"
>>>       vars:
>>>         get_attrs: "msg.records[*].{*volume: volume, state: state*}"
>>>       loop: "{{ ontap.results }}"
>>>       no_log: true
>>>     - name: volume size and utilize list
>>>       debug: var=Clusters
>>>
>>>
>>>
>>> *- name: copy csv data to file      copy:        dest:
>>> /home/u630850/facts/Clusters.csv        content: "{{ csv|join('\n') }}"*
>>> ...
>>>
>>> I am getting in Cluster variable output as below:( big list shored )
>>> Clusters:
>>>    10.250.198.160:
>>>    - state: online
>>>      volume: Dan_1
>>>    - state: online
>>>      volume: Dan_SVM_root
>>>    10.250.198.50:
>>>    - state: online
>>>      volume: Dan_root
>>>    - state: online
>>>      volume: Dan_root_ls01
>>>
>>> But I am getting in CSV file as an attachment.
>>>
>>> Once again, thank you so much. Looking forward for your reply
>>>
>>>
>>> On Sat, Sep 10, 2022 at 6:04 PM Vladimir Botka <[email protected]> wrote:
>>>
>>>> Create the list. Put the below declarations into *vars*
>>>>
>>>>   csv_query: '[].[`Clusters`, key, value[].node, value[].state]'
>>>>   csv: "{{ Clusters|dict2items|json_query(csv_query)|
>>>>            map('flatten')|map('join', ',')|list }}"
>>>>
>>>> gives
>>>>
>>>>   csv:
>>>>   - Clusters,192.168.1.1,node1,up
>>>>   - Clusters,192.168.1.2,node2,down
>>>>   - Clusters,192.168.1.3,node3,up
>>>>
>>>> Write the file
>>>>
>>>>   - copy:
>>>>       dest: /tmp/Clusters.csv
>>>>       content: "{{ csv|join('\n') }}"
>>>>
>>>> gives
>>>>
>>>> shell> cat /tmp/Clusters.csv
>>>> Clusters,192.168.1.1,node1,up
>>>> Clusters,192.168.1.2,node2,down
>>>> Clusters,192.168.1.3,node3,up
>>>>
>>>> --
>>>> Vladimir Botka
>>>>
>>>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CANGEjuXbJ6cpeTL1ynRbxUMecL2cz1u2o04OUM3ThmHic9wbHQ%40mail.gmail.com.

Reply via email to