Skip to content

Commit bafdd8a

Browse files
committed
Initial Version
1 parent 85413e0 commit bafdd8a

File tree

6 files changed

+386
-0
lines changed

6 files changed

+386
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Ansible Volume Management samples
2+
This folder contains to Ansible playbooks that can be used to manage volumes within a FSx for ONTAP file system.
3+
4+
They have been configured to use the new `use_lambda` feature that allows it to leverage an Workload Factory Link
5+
to issue the API calls to the FSx for ONTAP file system which alleviate the requirement of the Ansible control
6+
node to have network connectivity to the FSx for ONTAP file system. For more information on how to set up a
7+
Workload Factory Link, please refer to the [NetApp Workload Factory documentation](https://docs.netapp.com/us-en/workload-fsx-ontap/links-overview.html).
8+
9+
The list of playbooks included in this folder is as follows:
10+
- create\_volume.yaml
11+
- delete\_volume.yaml
12+
- create\_snapshot.yaml
13+
- delete\_snapshot.yaml
14+
15+
## Requirements
16+
- Ansible 2.9 or later. Installation instructions can be found [here](https://docs.ansible.com/ansible/latest/installation_guide/index.html)
17+
- NetApp ONTAP Ansible collection.
18+
- AWS Ansible collection.
19+
- An AWS secret with the credentials necessary to run the required volume APIs against the FSx for ONTAP file system. The required format of the secret is described below.
20+
21+
## Configuration
22+
Each playbook requires various variables to be set in order to run.
23+
| Variable | Used By Playbook | Required | Default | Description |
24+
|:-------- |:----------------:|:--------:|:-------:|:-----------|
25+
| volume\_name| All | Yes | None | The name of the volume you want to act one.|
26+
| volume\_size| create\_volume | Yes | None | The size, in MiBs, of the volume to create.|
27+
| vserver | All | Yes | None | The name of the vserver where the volume resides.|
28+
| fsxn\_hostname| All | Yes | None | The hostname or IP address of the FSxN where the volume resides.|
29+
| lambda\_function\_name| All | No | None | The name of the Workload Factory Link to use when issuing API calls to the FSx for ONTAP file system.|
30+
| aws\_region | All | No | None | The AWS region where the Link lambda function resides.|
31+
| secret\_name | Yes | All | The name of the AWS secret that contains the credentials to authenticate with the FSx for ONTAP file system.|
32+
| snapshot\_name | create\_snapshot | Yes | None | The name of the snapshot to create.|
33+
| security\_style | create\_volume | No | UNIX | The security style to use when creating the volume. Valid options are UNIX or NTFS.|
34+
| aggr | create\_volume | No | aggr1 | The name of the aggregate to create the volume on.|
35+
| volume\_type | create\_volume | No | RW | The type of volume to create. Valid options are RW and DP.|
36+
| junction\_path | create\_volume | No | `/<volume_name>` | The junction path to use when creating the volume.|
37+
38+
A convenient way to set all the required variable is to put them into a file named `varabless.yaml`.
39+
All the playbooks will attempt to load this file and use any variables defined in it. Otherwise,
40+
you can set them by using the `--extra-vars` flag when running the playbook.
41+
42+
So that you don't have to hardcode secrets into the playbook, or variable files, all the playbooks
43+
will leverage an AWS Secrets Manager secret to retrieve the credentials for FSx for ONTAP file system.
44+
45+
Each secret should have two `keys`:
46+
| Key | Value |
47+
| --- |:--- |
48+
| `username` | The username to use to authenticate with the FSx for ONTAP file system. |
49+
| `password` | The password to use to authenticate with the FSx for ONTAP file system. |
50+
51+
Since this script leverages the AWS Ansible collection you will need to provide authentication credentials for it.
52+
You can read more about how to do that [here](https://docs.ansible.com/ansible/latest/collections/amazon/aws/docsite/aws_ec2_guide.html#authentication).
53+
54+
## Author Information
55+
56+
This repository is maintained by the contributors listed on [GitHub](https://github.com/NetApp/FSx-ONTAP-samples-scripts/graphs/contributors).
57+
58+
## License
59+
60+
Licensed under the Apache License, Version 2.0 (the "License").
61+
62+
You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0).
63+
64+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an _"AS IS"_ basis, without WARRANTIES or conditions of any kind, either express or implied.
65+
66+
See the License for the specific language governing permissions and limitations under the License.
67+
68+
© 2026 NetApp, Inc. All Rights Reserved.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Title: snapshot_volume.yaml
2+
3+
---
4+
- name: Playbook to create a snapshot on a volume on an FSx for ONTAP file system.
5+
hosts: localhost
6+
collections:
7+
- netapp.ontap
8+
- amazon.aws
9+
gather_facts: false
10+
vars:
11+
use_lambda: false
12+
vars_files:
13+
- variables.yaml
14+
15+
tasks:
16+
- name: Ensure required variables are set.
17+
fail:
18+
msg: "Required variable '{{ item }}' has not been provided."
19+
when: vars[item] is undefined
20+
loop:
21+
- volume_name
22+
- snapshot_name
23+
- vserver
24+
- fsxn_hostname
25+
- secret_name
26+
27+
- name: Set use_lambda to true if lambda_function_name is provided.
28+
set_fact:
29+
use_lambda: true
30+
when: lambda_function_name is defined
31+
32+
- name: Set aws_profile to its default value of 'default' if not provided.
33+
set_fact:
34+
aws_profile: "default"
35+
when: aws_profile is not defined
36+
37+
- name: Ensure that aws_region has been provided if use_lambda is true.
38+
fail:
39+
msg: "aws_region must be defined when use_lambda is true."
40+
when: use_lambda and aws_region is not defined
41+
42+
- name: Set aws_region to "" if not set at this point.
43+
set_fact:
44+
aws_region: ""
45+
when: aws_region is not defined
46+
47+
- name: Set lambda_function_name to "" if not set at this point.
48+
set_fact:
49+
lambda_function_name: ""
50+
when: lambda_function_name is not defined
51+
52+
- name: Get username and password from AWS secret
53+
set_fact:
54+
username: "{{ lookup('amazon.aws.aws_secret', '{{ secret_name }}.username', nested=true) }}"
55+
password: "{{ lookup('amazon.aws.aws_secret', '{{ secret_name }}.password', nested=true) }}"
56+
no_log: true
57+
58+
- name: Create snapshot on volume
59+
netapp.ontap.na_ontap_snapshot:
60+
state: present
61+
volume: "{{ volume_name }}"
62+
vserver: "{{ vserver }}"
63+
snapshot: "{{ snapshot_name }}"
64+
use_lambda: "{{ use_lambda }}"
65+
lambda_config:
66+
aws_profile: "{{ aws_profile }}"
67+
aws_region: "{{ aws_region }}"
68+
function_name: "{{ lambda_function_name }}"
69+
hostname: "{{ fsxn_hostname }}"
70+
username: "{{ username }}"
71+
password: "{{ password }}"
72+
validate_certs: false
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Title: create_volume.yaml
2+
3+
---
4+
- name: Playbook to create a volumes on an FSx for ONTAP file system.
5+
hosts: localhost
6+
collections:
7+
- netapp.ontap
8+
- amazon.aws
9+
gather_facts: false
10+
vars_files:
11+
- variables.yaml
12+
vars:
13+
use_lambda: false
14+
15+
tasks:
16+
- name: Ensure required variables are set.
17+
fail:
18+
msg: "Required variable {{item}} has not been provided."
19+
when: vars[item] is undefined
20+
loop:
21+
- volume_name
22+
- volume_size
23+
- vserver
24+
- secret_name
25+
#
26+
# Give default values to optional variables if they are not defined
27+
- name: Set security_style to unix if not provide.
28+
set_fact:
29+
security_style: "unix"
30+
when: security_style is not defined
31+
32+
- name: Set aggr to 'aggr1' if not provided.
33+
set_fact:
34+
aggr: "aggr1"
35+
when: aggr is not defined
36+
37+
- name: Set volume_type to "rw" if not provided.
38+
set_fact:
39+
volume_type: "rw"
40+
when: volume_type is not defined
41+
42+
- name: Set use_lambda to true if lambda_function_name is provided.
43+
set_fact:
44+
use_lambda: true
45+
when: lambda_function_name is defined
46+
47+
- name: Set aws_provide to "default" if not provided.
48+
set_fact:
49+
aws_profile: "default"
50+
when: aws_profile is not defined
51+
52+
- name: Set junction path to "/<volume_name>" if not provided.
53+
set_fact:
54+
junction_path: "/{{ volume_name }}"
55+
when: junction_path is not defined
56+
57+
- name: Ensure that aws_region has been provided if use_lambda is true.
58+
fail:
59+
msg: "aws_region must be defined when use_lambda is true."
60+
when: use_lambda and aws_region is not defined
61+
62+
- name: Set aws_region to "" if not set at this point.
63+
set_fact:
64+
aws_region: ""
65+
when: aws_region is not defined
66+
67+
- name: Set lambda_function_name to "" if not set at this point.
68+
set_fact:
69+
lambda_function_name: ""
70+
when: lambda_function_name is not defined
71+
72+
- name: Get username and password from AWS secret.
73+
set_fact:
74+
username: "{{ lookup('amazon.aws.aws_secret', '{{ secret_name }}.username', nested=true) }}"
75+
password: "{{ lookup('amazon.aws.aws_secret', '{{ secret_name }}.password', nested=true) }}"
76+
no_log: true
77+
78+
- name: Create the volume
79+
netapp.ontap.na_ontap_volume:
80+
state: present
81+
name: "{{ volume_name }}"
82+
size: "{{ volume_size }}"
83+
vserver: "{{ vserver }}"
84+
aggregate_name: "{{ aggr }}"
85+
junction_path: "{{ junction_path }}"
86+
use_lambda: "{{ use_lambda }}"
87+
lambda_config:
88+
aws_profile: "{{ aws_profile }}"
89+
aws_region: "{{ aws_region }}"
90+
function_name: "{{ lambda_function_name }}"
91+
type: "{{ volume_type }}"
92+
size_unit: "mb"
93+
hostname: "{{ fsxn_hostname }}"
94+
username: "{{ username }}"
95+
password: "{{ password }}"
96+
validate_certs: false
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Title: delete_snapshot.yaml
2+
3+
---
4+
- name: Playbook to delete a snapshot from a volume on an FSx for ONTAP file system.
5+
hosts: localhost
6+
collections:
7+
- netapp.ontap
8+
- amazon.aws
9+
gather_facts: false
10+
vars:
11+
use_lambda: false
12+
vars_files:
13+
- variables.yaml
14+
15+
tasks:
16+
- name: Ensure required variables are set.
17+
fail:
18+
msg: "Required variable '{{ item }}' has not been provided."
19+
when: vars[item] is undefined
20+
loop:
21+
- volume_name
22+
- snapshot_name
23+
- vserver
24+
- fsxn_hostname
25+
- secret_name
26+
27+
- name: Set use_lambda to true if lambda_function_name is provided.
28+
set_fact:
29+
use_lambda: true
30+
when: lambda_function_name is defined
31+
32+
- name: Set aws_profile to its default value of 'default' if not provided.
33+
set_fact:
34+
aws_profile: "default"
35+
when: aws_profile is not defined
36+
37+
- name: Ensure that aws_region has been provided if use_lambda is true.
38+
fail:
39+
msg: "aws_region must be defined when use_lambda is true."
40+
when: use_lambda and aws_region is not defined
41+
42+
- name: Set aws_region to "" if not set at this point.
43+
set_fact:
44+
aws_region: ""
45+
when: aws_region is not defined
46+
47+
- name: Set lambda_function_name to "" if not set at this point.
48+
set_fact:
49+
lambda_function_name: ""
50+
when: lambda_function_name is not defined
51+
52+
- name: Get username and password from AWS secret
53+
set_fact:
54+
username: "{{ lookup('amazon.aws.aws_secret', '{{ secret_name }}.username', nested=true) }}"
55+
password: "{{ lookup('amazon.aws.aws_secret', '{{ secret_name }}.password', nested=true) }}"
56+
no_log: true
57+
58+
- name: Create snapshot on volume
59+
netapp.ontap.na_ontap_snapshot:
60+
state: absent
61+
volume: "{{ volume_name }}"
62+
vserver: "{{ vserver }}"
63+
snapshot: "{{ snapshot_name }}"
64+
use_lambda: "{{ use_lambda }}"
65+
lambda_config:
66+
aws_profile: "{{ aws_profile }}"
67+
aws_region: "{{ aws_region }}"
68+
function_name: "{{ lambda_function_name }}"
69+
hostname: "{{ fsxn_hostname }}"
70+
username: "{{ username }}"
71+
password: "{{ password }}"
72+
validate_certs: false
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Title: delete_volume.yaml
2+
3+
---
4+
- name: Playbook to delete a volume on an FSx for ONTAP file system.
5+
hosts: localhost
6+
collections:
7+
- netapp.ontap
8+
- amazon.aws
9+
gather_facts: false
10+
vars:
11+
use_lambda: false
12+
vars_files:
13+
- variables.yaml
14+
15+
tasks:
16+
- name: Ensure required variables are set.
17+
fail:
18+
msg: "Required variable {{item}} has not been provided."
19+
when: vars[item] is undefined
20+
loop:
21+
- volume_name
22+
- vserver
23+
- fsxn_hostname
24+
- secret_name
25+
26+
- name: Set use_lambda to true if lambda_function_name is provided.
27+
set_fact:
28+
use_lambda: true
29+
when: lambda_function_name is defined
30+
31+
- name: Set aws_profile to its default value of 'default' if not provided.
32+
set_fact:
33+
aws_profile: "default"
34+
when: aws_profile is not defined
35+
36+
- name: Ensure that aws_region has been provided if use_lambda is true.
37+
fail:
38+
msg: "aws_region must be defined when use_lambda is true."
39+
when: use_lambda and aws_region is not defined
40+
41+
- name: Set aws_region to "" if not set at this point.
42+
set_fact:
43+
aws_region: ""
44+
when: aws_region is not defined
45+
46+
- name: Set lambda_function_name to "" if not set at this point.
47+
set_fact:
48+
lambda_function_name: ""
49+
when: lambda_function_name is not defined
50+
51+
- name: Get username and password from AWS secret
52+
set_fact:
53+
username: "{{ lookup('amazon.aws.aws_secret', '{{ secret_name }}.username', nested=true) }}"
54+
password: "{{ lookup('amazon.aws.aws_secret', '{{ secret_name }}.password', nested=true) }}"
55+
no_log: true
56+
57+
- name: Delete the volume
58+
netapp.ontap.na_ontap_volume:
59+
state: absent
60+
name: "{{ volume_name }}"
61+
vserver: "{{ vserver }}"
62+
use_lambda: "{{ use_lambda }}"
63+
lambda_config:
64+
aws_profile: "{{ aws_profile }}"
65+
aws_region: "{{ aws_region }}"
66+
function_name: "{{ lambda_function_name }}"
67+
hostname: "{{ fsxn_hostname }}"
68+
username: "{{ username }}"
69+
password: "{{ password }}"
70+
validate_certs: false
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
volume_name: "vol1"
2+
volume_size: 100
3+
vserver: "fsx"
4+
fsxn_hostname: "10.0.0.13"
5+
lambda_function_name: "lambda-8nlmlCR"
6+
aws_region: "us-west-2"
7+
secret_name: "fsxn/default"
8+
snapshot_name: "snapshot1"

0 commit comments

Comments
 (0)