Skip to content

Commit c0a332a

Browse files
committed
Added CIFS Share examples.
1 parent 26ce4b5 commit c0a332a

6 files changed

Lines changed: 401 additions & 7 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
vserver: "{{ vserver }}"
8484
aggregate_name: "{{ aggr }}"
8585
junction_path: "{{ junction_path }}"
86+
volume_security_style: "{{ security_style }}"
8687
use_lambda: "{{ use_lambda }}"
8788
lambda_config:
8889
aws_profile: "{{ aws_profile }}"
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
#
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: Create the volume
84+
netapp.ontap.na_ontap_volume:
85+
state: present
86+
name: "{{ volume_name }}"
87+
size: "{{ volume_size }}"
88+
vserver: "{{ vserver }}"
89+
aggregate_name: "{{ aggr }}"
90+
junction_path: "{{ junction_path }}"
91+
volume_security_style: "{{ security_style }}"
92+
use_lambda: "{{ use_lambda }}"
93+
lambda_config:
94+
aws_profile: "{{ aws_profile }}"
95+
aws_region: "{{ aws_region }}"
96+
function_name: "{{ lambda_function_name }}"
97+
type: "{{ volume_type }}"
98+
size_unit: "mb"
99+
hostname: "{{ fsxn_hostname }}"
100+
username: "{{ username }}"
101+
password: "{{ password }}"
102+
validate_certs: false
103+
104+
- name: Create CIFS Share
105+
netapp.ontap.na_ontap_cifs:
106+
state: present
107+
name: "{{ share_name }}"
108+
path: "{{ junction_path }}"
109+
vserver: "{{ vserver }}"
110+
use_lambda: "{{ use_lambda }}"
111+
lambda_config:
112+
aws_profile: "{{ aws_profile }}"
113+
aws_region: "{{ aws_region }}"
114+
function_name: "{{ lambda_function_name }}"
115+
hostname: "{{ fsxn_hostname }}"
116+
username: "{{ username }}"
117+
password: "{{ password }}"
118+
validate_certs: false
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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+
#
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: Create the volume
84+
netapp.ontap.na_ontap_volume:
85+
state: absent
86+
name: "{{ volume_name }}"
87+
size: "{{ volume_size }}"
88+
vserver: "{{ vserver }}"
89+
aggregate_name: "{{ aggr }}"
90+
junction_path: "{{ junction_path }}"
91+
volume_security_style: "{{ security_style }}"
92+
use_lambda: "{{ use_lambda }}"
93+
lambda_config:
94+
aws_profile: "{{ aws_profile }}"
95+
aws_region: "{{ aws_region }}"
96+
function_name: "{{ lambda_function_name }}"
97+
type: "{{ volume_type }}"
98+
size_unit: "mb"
99+
hostname: "{{ fsxn_hostname }}"
100+
username: "{{ username }}"
101+
password: "{{ password }}"
102+
validate_certs: false
103+
104+
- name: Create CIFS Share
105+
netapp.ontap.na_ontap_cifs:
106+
state: absent
107+
name: "{{ share_name }}"
108+
path: "{{ junction_path }}"
109+
vserver: "{{ vserver }}"
110+
use_lambda: "{{ use_lambda }}"
111+
lambda_config:
112+
aws_profile: "{{ aws_profile }}"
113+
aws_region: "{{ aws_region }}"
114+
function_name: "{{ lambda_function_name }}"
115+
hostname: "{{ fsxn_hostname }}"
116+
username: "{{ username }}"
117+
password: "{{ password }}"
118+
validate_certs: false
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)