Python Discussions

Ansible Playbook error while calculating Next Volume Name

raj_shrivastava11

Hi, I have a below playbook wherein i am using gather info to get volumes and trying to get latest volume using Creation_time but it seems its not able to pick the volume with last creation time. Below is a playbook and error.

 

Error is coming while calculating QOS Policy name which like <vol_name>-premium.  Error is 

 

fatal: [localhost]: FAILED! => {
"msg": "An unhandled exception occurred while templating '{{ vol_name }}-premium'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '{{ vol_name }}'. Error was a <class 'ansible.errors.AnsibleError'>,

 

Playbook:

---
- hosts: localhost
collections:
- netapp.ontap
name: Datastore Creation
vars:
hostname: 10.220.58.171
username: admin
password: veritas123
vserver: segotx9015
aggr: segotx910_n1_aggr1
vol_name: "{{ vol_name }}"
time: []
qtree_name: segot_a2_x9015v0037
qos_policy: "{{ vol_name }}-premium"
snapshot_policy: "default"
disk_limit: 4
tasks:
- name: Limit Info Gathering to Volume and Lun Information
na_ontap_info:
state: info
gather_subset: "volume_info"
hostname: "{{ hostname }}"
username: "{{ username }}"
password: "{{ password }}"
https: true
validate_certs: false
register: ontap
- name: Using set_fact
set_fact:
time: "{{ time }} + ['{{ ontap.ontap_info.volume_info[item].volume_id_attributes.creation_time }}' ]"
loop: "{{ ontap.ontap_info.volume_info }}"
set_fact:
newest: "{{ time|max }}"
vol_name: "{{ ontap.ontap_info.volume_info[item].volume_id_attributes.name }}"
with_items: "{{ ontap.ontap_info.volume_info }}"
when:
- ontap.ontap_info.volume_info[item].volume_id_attributes.creation_time == "newest"
- name: Create Qos Policy Group
na_ontap_qos_policy_group:
state: present
name: "{{ qos_policy }}"
vserver: "{{ vserver }}"
max_throughput: 240MB/s
min_throughput:
hostname: "{{ hostname }}"
username: "{{ username }}"
password: "{{ password }}"
- name: Create Primary Volume
na_ontap_volume:
state: present
name: "{{ vol_name }}"
vserver: "{{ vserver }}"
aggregate_name: "{{ aggr }}"
size: "{{ disk_limit + 1 }}"
size_unit: tb
policy: default
volume_security_style: unix
junction_path: "/{{ vol_name }}"
qos_policy_group: "{{ qos_policy }}"
snapshot_policy: "{{ snapshot_policy }}"
hostname: "{{ hostname }}"
username: "{{ username }}"
password: "{{ password }}"
https: true
validate_certs: false
- name: Create Export Policy
na_ontap_export_policy:
state: present
name: "{{ qtree_name }}"
vserver: "{{ vserver }}"
hostname: "{{ hostname }}"
username: "{{ username }}"
password: "{{ password }}"
https: true
validate_certs: false
- name: Create ExportPolicyRule
na_ontap_export_policy_rule:
state: present
name: "{{ qtree_name }}"
vserver: "{{ vserver }}"
client_match: 10.221.102.64/26,10.221.102.0/26
ro_rule: sys
rw_rule: sys
protocol: nfs
super_user_security: any
allow_suid: true
hostname: "{{ hostname }}"
username: "{{ username }}"
password: "{{ password }}"
https: true
validate_certs: false
- name: Create Qtrees
na_ontap_qtree:
state: present
name: "{{ qtree_name }}"
flexvol_name: "{{ vol_name }}"
vserver: "{{ vserver }}"
export_policy: "{{ qtree_name }}"
hostname: "{{ hostname }}"
username: "{{ username }}"
password: "{{ password }}"
https: true
validate_certs: false
- name: Add/Set quota
na_ontap_quotas:
state: present
vserver: "{{ vserver }}"
volume: "{{ vol_name }}"
quota_target: "/vol/{{ vol_name }}/{{ qtree_name }}"
type: tree
policy: default
disk_limit: "{{ disk_limit*1024*1024*1024 }}"
set_quota_status: True
hostname: "{{ hostname }}"
username: "{{ username }}"
password: "{{ password }}"

 

1 REPLY 1

raj_shrivastava11

I have been able to complete this with help of Netapp colleagues in Slack.

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public