#How do you use <<: *login to shorten code?

1 messages · Page 1 of 1 (latest)

rugged eagle
#

I've seen this embedded in some examples in the Ansible documentation for na_ontap_info module. I "think" something like defaults_module is used but I don't know how to format that. Are there any examples out there? It would be nice to not have to repeat username, password, and hostname vars over and over in writing my code.

rose patio
#

From one of internal playbook you'll have something like this

`- name: Get info
hosts: localhost
gather_facts: false
collections:
- netapp.ontap
vars_files:
vars/validation_loops.yml
vars:
validate_loop_idempotency: "{{ validate_check_mode_and_idempotency }}"
vserver: ansibleSVM
volume: test
aggr: aggr1
hostname:
- 10.X.X.X # 9.13.1
- 10.X.X.X # 9.10.1
- 10.X.X.X # 9.8
- 10.X.X.X # 9.7
module_defaults:
group/netapp.ontap.netapp_ontap:
vserver: "{{ vserver }}"
hostname: "{{ hostname[1] }}"
username: admin
password: XXX
https: true
validate_certs: false
use_rest: always

tasks:
- name: Create bucket in 9.7
na_ontap_s3_buckets:
state: present
name: carchi-test-bucket
comment: test-bucket
size: 838860800
hostname: "{{ hostname[2] }}"
ignore_errors: true
register: result
- name: check outcomes
assert: { that: "'Error: na_ontap_s3_bucket only supports REST, and requires ONTAP 9.8.0 or later. Found: 9.7.0.' in result['msg']"}`

#

So anytime a netapp.ontap.netapp_ontap module is call these default aer passed in

#

If you want to over ride it you can pass in another variable on top. For instance we are overriding the hostname in the s3 task

rugged eagle
#

Interesting

#

@rose patio so for "group/netapp.ontap.netapp_ontap", it is basically saying:
create a group in defaults_module for the collection netapp.ontap for any module with "netapp_ontap"?
Am I getting that right? I just updated a test playbook and it ran perfectly btw.