#How to Loop through all nodes of a cluster

1 messages · Page 1 of 1 (latest)

arctic chasm
#

Can someone please share a sample of code that pulls all the node names from a cluster (presumably using na_ontap_rest_info) and runs a command against every node of that cluster?

I am currently trying to disable disk auto assign on all nodes of the cluster (na_ontap_disk_option), but can't seem to wrap my head around how to loop through the output of the rest_info.

vast peak
#

Hey @arctic chasm, this playbook should do what you're looking for:

---
- name: Disable disk auto-assign on all nodes in the cluster
  hosts: localhost
  connection: local
  gather_facts: false
  collections:
    - netapp.ontap

  vars:
    login: &login
      hostname: "cluster1"
      username: "admin"
      password: "*****"
      https: yes
      validate_certs: no

  tasks:
    - name: Get list of nodes in the cluster
      na_ontap_rest_info:
        <<: *login
        gather_subset:
          - cluster/nodes
      register: node_list

    - name: Disable disk auto-assign on all nodes
      na_ontap_disk_options:
        <<: *login
        node: "{{ item.name }}"
        autoassign: false
      loop: "{{ node_list['ontap_info']['cluster/nodes']['records'] }}"
#

let me know if it works out for you

arctic chasm
#

Thank you, @vast peak ! That's exactly what I was looking for! I was close!