NetApp ONTAP Ansible playbook working for single cluster, but failing with inventory file setup

158 Views Asked by At

Ansible inventory netapp.ontap

I just started to test my first playbooks in Ansible but unfortunately I already fail while setting up an inventory. I am trying to use the module na_ontap_ssh_command (netapp.ontap collection) to run the version command on a NetApp cluster.

The playbook works for a single cluster but as soon as I try to set up an inventory file it does not work.

This works:

---
- hosts: localhost
  collections:
    - netapp.ontap
  name: Cluster ONTAP Version
  vars:
    login: &login
      hostname: cluster1
      username: "{{ netapp_username }}"
      password: "{{ netapp_password }}"
      validate_certs: true
  vars_files:
    - secret.yml

 
  tasks:

  - name: cli Command
    netapp.ontap.na_ontap_ssh_command:
      command: version
      <<: *login
    register: cluster_version

  - name: Print Output
    debug:
      var: cluster_version['stdout_lines_filtered']

I tried to set up the playbook and inventory file according to https://netapp.io/2019/07/17/running-a-playbook-against-multiple-ontap-clusters/ but it does not work:

inventory.yml
cluster1
cluster2
---
- hosts: all
  gather_facts: false
  collections:
    - netapp.ontap
  name: Cluster ONTAP Version
  vars:
   login: &login
      hostname: "{{ inventory_hostname }}"
      username: "{{ netapp_username }}"
      password: "{{ netapp_password }}"
      validate_certs: true
  vars_files:
    - secret.yml

  tasks:
  - name: Version CLI Command
    netapp.ontap.na_ontap_ssh_command:  
      command: version
      <<: *login
    connection: local
    register: cluster_version
    
  - name: Print Output
    debug:
      var: cluster_version['stdout_lines_filtered']

Error message I get is: "the python paramiko module is required" But paramiko is installed and works for a single cluster.

Can anyone please help how to set up an inventory for netapp.ontap modules?

1

There are 1 best solutions below

0
john.w On

Try removing "connection: local" from the task and instead moving it to the play level:

---
- hosts: all  
  gather_facts: false  
  connection: local  
  collections:    
    - netapp.ontap  
  name: Cluster ONTAP Version

This has the added benefit of being less tedious as well.

I would recommend also ensuring you are using a new enough version of Ansible to use module defaults as well. https://netapp.io/2022/02/15/ansible-module-defaults-the-ansible-specific-alternative-to-yaml-aliases/

Here is what that would look like all together

---
- hosts: all
  gather_facts: false
  connection: local  
  collections:
    - netapp.ontap
  name: Cluster ONTAP Version
  module_defaults:    
    group/netapp.ontap.netapp_ontap:      
      hostname: "{{ inventory_hostname }}"      
      username: "{{ netapp_username }}"      
      password: "{{ netapp_password }}"     
      validate_certs: true
  vars_files:
    - secret.yml

  tasks:
  - name: Version CLI Command
    netapp.ontap.na_ontap_ssh_command:  
      command: version
    register: cluster_version
    
  - name: Print Output
    debug:
      var: cluster_version['stdout_lines_filtered']