Up until now YAML aliases were the only way to avoid having to retype out all the connection lines for NetApp ONTAP modules, so a playbook looked something like this:

---
- hosts: localhost
  collections:
  - netapp.ontap
  vars:
    login: &login
      hostname: cluster1.local.lab
      username: admin
      password: netapp123
      https: true
      validate_certs: false
  tasks:
  - name: info gather
    na_ontap_rest_info:
      subset: volume_info
      <<: *login

This worked, however it didn’t always work between roles, and it still required you to add that <<: *login line to each task.

Beginning with Ansible Core 2.12 (Ansible 5) you can now use module defaults. Module defaults are a section that lets you set defaults for inputs for any modules from a collection.  It is made from a new meta section in the Ansible playbook.  Now the above playbook could look like this:

---
- hosts: localhost
  collections:
  - netapp.ontap
  module_defaults:
    group/netapp.ontap.netapp_ontap:
      hostname: cluster1.local.lab
      username: admin
      password: netapp123
      https: true
      validate_certs: false
  tasks:
  - name: info gather
    na_ontap_rest_info:
      subset: volume_info

The values propagate automatically to all modules in the collections.  A few advantages over <<: *login

  • It does not look so ugly.
  • You don't need to repeat <<: *loginin every task.
  • You can override a value in a task without a warning about duplicate variable.

Just remember, this is only for Ansible Core 2.12 and higher.  You may need to update your Ansible engine if you use the command line, or if you use AWX you will need an Execution Environment built with that version of Ansible.

  • At the time of this writing, default built Execution Environments are still on 2.11 so the schmots1/na_ansible_ee doesn’t support this yet. This will be fixed as soon as the Ansible development team updates that build stack.

NetApp.io is your home for Ansible on NetApp news and so much more.  Also join our Slack workspace (https://www.netapp.io/slack)

About David Blackwell

David is a twenty year IT veteran who has been an admin for just about every aspect of a DataCenter at one time or another. When not working, or tinkering with new software at home, David spends most of his free time with his six year old son and his lovely wife.

Pin It on Pinterest