#Best practice for ansible playbooks across different clusters

1 messages · Page 1 of 1 (latest)

vivid sleet
#

I am trying to create volumes and LUNs across different NetApp ONTAP 9.13.1 clusters. For the moment my work manages one cluster and I have my connection details set with:

in my role main playbook:
module_defaults: group/netapp.ontap.netapp_ontap: hostname: "{{ clusterip }}" username: "{{ user }}" password: "{{ pass }}" https: "{{ https_option }}" validate_certs: "{{ validate_certs_option }}" use_rest: always

but if I want to create a LUN in a specific cluster I might need to use the :

vars: cluster1: &cluster1 hostname: "{{ clusterip }}" username: "{{ user }}" password: "{{ pass }}" https: "{{ https_option }}" validate_certs: "{{ validate_certs_option }}"

and in every netapp task in all my tasks playbooks: I will use something similar to this:

- name: Create LUN na_ontap_lun: <<: *cluster1 name: "cluster_1-luntest"

but if I want to keep the task general and customisable for all clusters I want to be able to have

- name: Create LUN na_ontap_lun: <<: *login name: "{{ cluster_number }}-luntest"

and login will point to the right cluster credentials depending on {{ cluster_number }}, and there would be no need to repeat the task N times ( N being number of clusters ) to create a LUN with the correct login credentials.

How can this be achieved or what is the best practice for handling resource creation in multi cluster environment?

swift arrow
#

I typically do something like for my ONTAP playbooks:

- hosts: "{{ target_cluster }}"
connection: local
gather_facts: no
collections:
- netapp.ontap

And then the vars for the cluster like you have:

vars:
clusterlogin: &clusterlogin
hostname: "{{ cluster_mgmt_ip }}"
username: "{{ cluster_mgmt_username }}"
password: "{{ cluster_mgmt_password }}"
https: true
validate_certs: no

Then for each task I'll have similar to you.

- name: Create NAS Volume
netapp.ontap.na_ontap_volume:
<<: *clusterlogin
state: "{{ item.state }}"
vserver: "{{ item.vserver }}"
name: "{{ item.name }}"
aggregate_name: "{{ item.aggr }}"

I have my inventory.yml setup with a hierarchy and various groups. When I run the playbook I passs the "{{ target_cluster }}" in the command. Be it "all", or a group, or a specific cluster.

Such as:

ansible-playbook -i inventory.yml create_volume.yml --extra-vars "target_cluster=test-cluster1"