Skip to content

Commit 6407c9b

Browse files
authored
Merge pull request #276 from NetApp/add_cifs_share_create_examples
Added CIFS Share Ansible and Terraform examples.
2 parents 26ce4b5 + dabc788 commit 6407c9b

11 files changed

Lines changed: 419 additions & 27 deletions

File tree

Infrastructure_as_Code/Ansible/Volume_Management/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ node to have network connectivity to the FSx for ONTAP file system. For more inf
77
Workload Factory Link, please refer to the [NetApp Workload Factory documentation](https://docs.netapp.com/us-en/workload-fsx-ontap/links-overview.html).
88

99
The list of playbooks included in this folder is as follows:
10-
- create\_volume.yaml
11-
- delete\_volume.yaml
1210
- create\_snapshot.yaml
1311
- delete\_snapshot.yaml
12+
- create\_volume.yaml
13+
- delete\_volume.yaml
14+
- create\_volume\_and\_share.yaml
15+
- delete\_volume\_and\_share.yaml
1416

1517
## Requirements
1618
- Ansible 2.9 or later. Installation instructions can be found [here](https://docs.ansible.com/ansible/latest/installation_guide/index.html)
@@ -28,11 +30,11 @@ Each playbook requires various variables to be set in order to run.
2830
| volume\_name| All | Yes | None | The name of the volume you want to act on.|
2931
| lambda\_function\_name| All | No | None | The name of the Workload Factory Link Lambda function to use when issuing API calls to the FSx for ONTAP file system.|
3032
| aws\_region | All | No | None | The AWS region where the Lambda function resides.|
31-
| volume\_size| create\_volume | Yes | None | The size, in MiBs, of the volume to create.|
32-
| security\_style | create\_volume | No | UNIX | The security style to use when creating the volume. Valid options are UNIX or NTFS.|
33-
| aggr | create\_volume | No | aggr1 | The name of the aggregate to create the volume on.|
34-
| volume\_type | create\_volume | No | RW | The type of volume to create. Valid options are RW and DP.|
35-
| junction\_path | create\_volume | No | `/<volume_name>` | The junction path to use when creating the volume.|
33+
| volume\_size| create\_volume\* | Yes | None | The size, in MiBs, of the volume to create.|
34+
| security\_style | create\_volume\* | No | UNIX | The security style to use when creating the volume. Valid options are UNIX or NTFS.|
35+
| aggr | create\_volume\* | No | aggr1 | The name of the aggregate to create the volume on.|
36+
| volume\_type | create\_volume\* | No | RW | The type of volume to create. Valid options are RW and DP.|
37+
| junction\_path | create\_volume\* | No | `/<volume_name>` | The junction path to use when creating the volume.|
3638
| snapshot\_name | create\_snapshot | Yes | None | The name of the snapshot to create.|
3739

3840
A convenient way to set all the required variable is to put them into a file named `variables.yaml`.

Infrastructure_as_Code/Ansible/Volume_Management/create_volume.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
- volume_size
2323
- vserver
2424
- secret_name
25+
- fsxn_hostname
2526
#
2627
# Give default values to optional variables if they are not defined
27-
- name: Set security_style to unix if not provide.
28+
- name: Set security_style to unix if not provided.
2829
set_fact:
2930
security_style: "unix"
3031
when: security_style is not defined
@@ -44,7 +45,7 @@
4445
use_lambda: true
4546
when: lambda_function_name is defined
4647

47-
- name: Set aws_provide to "default" if not provided.
48+
- name: Set aws_profile to "default" if not provided.
4849
set_fact:
4950
aws_profile: "default"
5051
when: aws_profile is not defined
@@ -83,6 +84,7 @@
8384
vserver: "{{ vserver }}"
8485
aggregate_name: "{{ aggr }}"
8586
junction_path: "{{ junction_path }}"
87+
volume_security_style: "{{ security_style }}"
8688
use_lambda: "{{ use_lambda }}"
8789
lambda_config:
8890
aws_profile: "{{ aws_profile }}"
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Title: create_volume_and_share.yaml
2+
3+
---
4+
- name: Playbook to create a volume and a CIFS share that points to it 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+
- fsxn_hostname
26+
#
27+
# Give default values to optional variables if they are not defined
28+
- name: Set security_style to ntfs if not provided.
29+
set_fact:
30+
security_style: "ntfs"
31+
when: security_style is not defined
32+
33+
- name: Set aggr to 'aggr1' if not provided.
34+
set_fact:
35+
aggr: "aggr1"
36+
when: aggr is not defined
37+
38+
- name: Set volume_type to "rw" if not provided.
39+
set_fact:
40+
volume_type: "rw"
41+
when: volume_type is not defined
42+
43+
- name: Set use_lambda to true if lambda_function_name is provided.
44+
set_fact:
45+
use_lambda: true
46+
when: lambda_function_name is defined
47+
48+
- name: Set aws_profile to "default" if not provided.
49+
set_fact:
50+
aws_profile: "default"
51+
when: aws_profile is not defined
52+
53+
- name: Set junction_path to "/<volume_name>" if not provided.
54+
set_fact:
55+
junction_path: "/{{ volume_name }}"
56+
when: junction_path is not defined
57+
58+
- name: Set share_name to "<volume_name>" if not provided.
59+
set_fact:
60+
share_name: "{{ volume_name }}"
61+
when: share_name is not defined
62+
63+
- name: Ensure that aws_region has been provided if use_lambda is true.
64+
fail:
65+
msg: "aws_region must be defined when use_lambda is true."
66+
when: use_lambda and aws_region is not defined
67+
68+
- name: Set aws_region to "" if not set at this point.
69+
set_fact:
70+
aws_region: ""
71+
when: aws_region is not defined
72+
73+
- name: Set lambda_function_name to "" if not set at this point.
74+
set_fact:
75+
lambda_function_name: ""
76+
when: lambda_function_name is not defined
77+
78+
- name: Get username and password from AWS secret.
79+
set_fact:
80+
username: "{{ lookup('amazon.aws.aws_secret', '{{ secret_name }}.username', nested=true) }}"
81+
password: "{{ lookup('amazon.aws.aws_secret', '{{ secret_name }}.password', nested=true) }}"
82+
no_log: true
83+
84+
- name: Create the volume
85+
netapp.ontap.na_ontap_volume:
86+
state: present
87+
name: "{{ volume_name }}"
88+
size: "{{ volume_size }}"
89+
vserver: "{{ vserver }}"
90+
aggregate_name: "{{ aggr }}"
91+
junction_path: "{{ junction_path }}"
92+
volume_security_style: "{{ security_style }}"
93+
use_lambda: "{{ use_lambda }}"
94+
lambda_config:
95+
aws_profile: "{{ aws_profile }}"
96+
aws_region: "{{ aws_region }}"
97+
function_name: "{{ lambda_function_name }}"
98+
type: "{{ volume_type }}"
99+
size_unit: "mb"
100+
hostname: "{{ fsxn_hostname }}"
101+
username: "{{ username }}"
102+
password: "{{ password }}"
103+
validate_certs: false
104+
105+
- name: Create CIFS Share
106+
netapp.ontap.na_ontap_cifs:
107+
state: present
108+
name: "{{ share_name }}"
109+
path: "{{ junction_path }}"
110+
vserver: "{{ vserver }}"
111+
use_lambda: "{{ use_lambda }}"
112+
lambda_config:
113+
aws_profile: "{{ aws_profile }}"
114+
aws_region: "{{ aws_region }}"
115+
function_name: "{{ lambda_function_name }}"
116+
hostname: "{{ fsxn_hostname }}"
117+
username: "{{ username }}"
118+
password: "{{ password }}"
119+
validate_certs: false
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Title: delete_volume_and_share.yaml
2+
3+
---
4+
- name: Playbook to delete a volume and a CIFS share that points to it 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+
- vserver
23+
- secret_name
24+
- fsxn_hostname
25+
#
26+
# Give default values to optional variables if they are not defined
27+
- name: Set security_style to ntfs if not provide.
28+
set_fact:
29+
security_style: "ntfs"
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: Set share_name to "<volume_name>" if not provided.
58+
set_fact:
59+
share_name: "{{ volume_name }}"
60+
when: share_name is not defined
61+
62+
- name: Ensure that aws_region has been provided if use_lambda is true.
63+
fail:
64+
msg: "aws_region must be defined when use_lambda is true."
65+
when: use_lambda and aws_region is not defined
66+
67+
- name: Set aws_region to "" if not set at this point.
68+
set_fact:
69+
aws_region: ""
70+
when: aws_region is not defined
71+
72+
- name: Set lambda_function_name to "" if not set at this point.
73+
set_fact:
74+
lambda_function_name: ""
75+
when: lambda_function_name is not defined
76+
77+
- name: Get username and password from AWS secret.
78+
set_fact:
79+
username: "{{ lookup('amazon.aws.aws_secret', '{{ secret_name }}.username', nested=true) }}"
80+
password: "{{ lookup('amazon.aws.aws_secret', '{{ secret_name }}.password', nested=true) }}"
81+
no_log: true
82+
83+
- name: Delete CIFS Share
84+
netapp.ontap.na_ontap_cifs:
85+
state: absent
86+
name: "{{ share_name }}"
87+
path: "{{ junction_path }}"
88+
vserver: "{{ vserver }}"
89+
use_lambda: "{{ use_lambda }}"
90+
lambda_config:
91+
aws_profile: "{{ aws_profile }}"
92+
aws_region: "{{ aws_region }}"
93+
function_name: "{{ lambda_function_name }}"
94+
hostname: "{{ fsxn_hostname }}"
95+
username: "{{ username }}"
96+
password: "{{ password }}"
97+
validate_certs: false
98+
99+
- name: Delete the volume
100+
netapp.ontap.na_ontap_volume:
101+
state: absent
102+
name: "{{ volume_name }}"
103+
vserver: "{{ vserver }}"
104+
aggregate_name: "{{ aggr }}"
105+
use_lambda: "{{ use_lambda }}"
106+
lambda_config:
107+
aws_profile: "{{ aws_profile }}"
108+
aws_region: "{{ aws_region }}"
109+
function_name: "{{ lambda_function_name }}"
110+
hostname: "{{ fsxn_hostname }}"
111+
username: "{{ username }}"
112+
password: "{{ password }}"
113+
validate_certs: false

Infrastructure_as_Code/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ This folder contains code samples and automation scripts for FSx for NetApp ONTA
77
* [SnapMirror report](Ansible/snapmirror_report)
88
* [Volume Management](Ansible/Volume_Management)
99
* [CloudFormation](CloudFormation)
10-
* [NetApp-FSxN-Custom-Resources-Samples](CloudFormation/NetApp-FSxN-Custom-Resources-Samples)
10+
* [Deploy-fsx-ontap](CloudFormation/deploy-fsx-ontap)
1111
* [Export FSx for ONTAP Configuration to CloudFormation](CloudFormation/Export-FSxN-CloudFormation)
12-
* [deploy-fsx-ontap](CloudFormation/deploy-fsx-ontap)
12+
* [NetApp-FSxN-Custom-Resources-Samples](CloudFormation/NetApp-FSxN-Custom-Resources-Samples)
1313
* [Terraform](Terraform)
14+
* [Deployment of FSx ONTAP with VPN for File Share Access](Terraform/deploy-fsx-ontap-fileshare-access)
15+
* [Deployment of SQL Server on EC2 with FSx ONTAP](Terraform/deploy-fsx-ontap-sqlserver)
1416
* [FSx ONTAP deployment using Terraform](Terraform/deploy-fsx-ontap)
1517
* [FSx ONTAP Replication](Terraform/fsxn-replicate)
16-
* [Deployment of SQL Server on EC2 with FSx ONTAP](Terraform/deploy-fsx-ontap-sqlserver)
17-
* [Deployment of FSx ONTAP with VPN for File Share Access](Terraform/deploy-fsx-ontap-fileshare-access)
18+
* [Miscellaneous FSx ONTAP operations using Terraform](Terraform/Miscellaneous)
1819

1920
## Author Information
2021

@@ -31,4 +32,4 @@ is distributed on an _"AS IS"_ basis, without WARRANTIES or conditions of any ki
3132

3233
See the License for the specific language governing permissions and limitations under the License.
3334

34-
© 2024 NetApp, Inc. All Rights Reserved.
35+
© 2026 NetApp, Inc. All Rights Reserved.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Miscellaneous Terraform Examples
2+
This subfolder contains various examples of how you can use Terraform to manage an FSx for ONTAP file system.
3+
4+
| Example | Description |
5+
| --- | --- |
6+
| [Create CIFS Share](create_cifs_share.tf) | This sample shows how to create a volume and a CIFS share that points to it on an FSx for ONTAP file system. |
7+
8+
## Author Information
9+
10+
This repository is maintained by the contributors listed on [GitHub](https://github.com/NetApp/FSx-ONTAP-samples-scripts/graphs/contributors).
11+
12+
## License
13+
14+
Licensed under the Apache License, Version 2.0 (the "License").
15+
16+
You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0).
17+
18+
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.
19+
20+
See the License for the specific language governing permissions and limitations under the License.
21+
22+
© 2024 NetApp, Inc. All Rights Reserved.

0 commit comments

Comments
 (0)