Skip to content

Commit b1c5276

Browse files
committed
Initial Version
1 parent a91bf31 commit b1c5276

File tree

6 files changed

+179
-1
lines changed

6 files changed

+179
-1
lines changed

Ansible/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Ansible Samples
2+
Ansible is a general purpose automation engine. It can be used to automate most repetitive IT tasks.
3+
The typical input you provide Ansible is a "Playbook." This folder holds various playbooks that can be used
4+
to help automate tasks around the management of a FSx for ONTAP file system.
5+
Click here for more information an [Ansible](https://www.ansible.com/).
6+
7+
| Tool | Description |
8+
| --- | --- |
9+
| [Inventory Report](./fsx_inventory_report) | Creates a report of all the FSxN file systems within an AWS account.|
10+
| [SnapMirror Report](./snapmirror_report) | Creates a report of all SnapMirror relationships within all the FSxN file systems within an AWS account.|
11+
12+
## Author Information
13+
14+
This repository is maintained by the contributors listed on [GitHub](https://github.com/NetApp/FSx-ONTAP-samples-scripts/graphs/contributors).
15+
16+
## License
17+
18+
Licensed under the Apache License, Version 2.0 (the "License").
19+
20+
You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0).
21+
22+
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.
23+
24+
See the License for the specific language governing permissions and limitations under the License.
25+
26+
© 2024 NetApp, Inc. All Rights Reserved.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Ansible Inventory Report
2+
This Ansible playbook generates a report of all the FSx for ONTAP file systems within an AWS account.
3+
In includes all the SVMs and Volumes.
4+
5+
## Requirements
6+
- Ansible 2.9 or later
7+
- AWS Ansible collection
8+
9+
## Installation
10+
There are three files used to create the report:
11+
- `generate_report.yaml`: The Ansible playbook that generates the report.
12+
- `processs_region.yaml`: A collection of tasks that will process all the FSxNs in a region.
13+
- `get_all_fsxn_regions.yaml`: A collection of tasks that retrieves all the AWS regions, that are enabled for the account, where FSx for ONTAP is available.
14+
15+
## Configuration
16+
There are a variable that can be changed at the top of the `generate_report.yaml` file:
17+
- report\_name - Sets the file path of the report that will be generated.
18+
19+
## Usage
20+
To generate the report, run the following command:
21+
```bash
22+
ansible-playbook generate_report.yaml
23+
```
24+
25+
## Output
26+
After a successful run, the report will be saved to the file path specified in the `report_name` variable.
27+
The fommat of the report is as follows:
28+
```
29+
Region: <region_name>
30+
File System ID: <file-system-id-1>
31+
SVM ID: <svm-id-1-1>
32+
Volumes:
33+
<volume-id-1-1-1> <volume-size-in-megabytes> <security-style> <volume-type>
34+
<volume-id-1-1-2> <volume-size-in-megabytes> <security-style> <volume-type>
35+
SVM ID: <svm-id-1-2>
36+
Volumes:
37+
<volume-id-1-1-1> <volume-size-in-megabytes> <security-style> <volume-type>
38+
<volume-id-1-1-2> <volume-size-in-megabytes> <security-style> <volume-type>
39+
File System ID: <file-system-id-2>
40+
SVM ID: <svm-id-2-1>
41+
Volumes:
42+
<volume-id-2-1-1> <volume-size-in-megabytes> <security-style> <volume-type>
43+
<volume-id-2-1-2> <volume-size-in-megabytes> <security-style> <volume-type>
44+
SVM ID: <svm-id-2-2>
45+
Volumes:
46+
<volume-id-2-2-1> <volume-size-in-megabytes> <security-style> <volume-type>
47+
<volume-id-2-2-2> <volume-size-in-megabytes> <security-style> <volume-type>
48+
```
49+
Where:
50+
- \<volume-size-in-megabytes> is the provisioned size of the volume in megabytes.
51+
- \<security-style> is the security style of the volume (e.g. UNIX, NTFS).
52+
- \<volume-type> is the type of the volume (e.g. RW, DP).
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+
© 2024 NetApp, Inc. All Rights Reserved.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#
2+
# This Ansible playbook generates a SnapMirror lag time report for all the
3+
# SnapMirror relationships, in all the FSxNs, in all regions,
4+
#################################################################################
5+
---
6+
- vars:
7+
report_name: output.csv
8+
secrets_list_file: secrets.csv
9+
secrets_region: us-west-2
10+
#################################################################################
11+
#
12+
# Don't change anything below this line.
13+
#
14+
#################################################################################
15+
fsxn_regions: []
16+
opted_in_regions: []
17+
18+
name: Playbook to generate a SnapMirror report on all the FSxNs.
19+
hosts: localhost
20+
collections:
21+
- amazon.aws
22+
gather_facts: false
23+
24+
tasks:
25+
- name: Delete previous report while adding the header line.
26+
ansible.builtin.shell:
27+
cmd: echo fs,source,destination,state,healthy,lag_time > {{ report_name }}
28+
29+
- name: Get all the regions that support FSxN that I am opted into.
30+
include_tasks: get_fsxn_regions.yaml
31+
32+
- name: Generate the report for all the FSxNs.
33+
include_tasks: process_region.yaml
34+
loop: "{{ fsxn_regions }}"
35+
loop_control:
36+
loop_var: region
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
- name: Get all the opted-in regions
2+
amazon.aws.aws_region_info:
3+
register: region_info
4+
5+
- name: Get region names
6+
set_fact:
7+
enabled_regions: "{{ region_info.regions | map(attribute='region_name') | list }}"
8+
9+
- name: Get the capabilities of all regions
10+
set_fact:
11+
regions_capabilities: "{{ lookup('ansible.builtin.url', 'https://api.regional-table.region-services.aws.a2z.com/index.json', split_lines=false) }}"
12+
13+
- name: Filter regions that support FSxN and are opted-in
14+
set_fact:
15+
fsxn_regions: >-
16+
{{
17+
regions_capabilities.prices
18+
| selectattr("attributes.aws:serviceName", "equalto", "Amazon FSx for NetApp ONTAP")
19+
| selectattr("attributes.aws:region", "in", enabled_regions)
20+
| map(attribute="attributes.aws:region")
21+
| list
22+
}}
23+
24+
- name: Output the FSxN regions
25+
debug:
26+
msg: "fsxn_regions={{ fsxn_regions }}"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Since Ansible can't handle nested loops, this is a block of tasked that is run
3+
# for each region. It assume that the calling playbook used 'region' as its loop variable.
4+
---
5+
- name: Get all the FSxNs for the specified region.
6+
ansible.builtin.shell:
7+
cmd: aws fsx describe-file-systems --region {{ region }} --query 'FileSystems[*].{FileSystemId:FileSystemId}' --output text | sed -e '/^$/d'
8+
register: fsxn_ids_per_region
9+
10+
- name: Get all the SVMs and volumes for each FSxN.
11+
ansible.builtin.shell:
12+
cmd: |
13+
echo "Region: {{ region }}" >> {{ report_name }};
14+
fs={{ item }};
15+
echo " File System ID: ${fs}" >> {{ report_name }};
16+
svms=$(aws fsx describe-storage-virtual-machines --filters Name=file-system-id,Values=${fs} --region {{ region }} --output=text --query 'StorageVirtualMachines[*].StorageVirtualMachineId');
17+
for svm in $svms; do
18+
echo " SVM ID: ${svm}" >> {{ report_name }};
19+
echo " Volume IDs:" >> {{ report_name }};
20+
aws fsx describe-volumes --filters Name=storage-virtual-machine-id,Values=${svm} --region {{ region }} --output=text --query 'Volumes[*].{Size: OntapConfiguration.SizeInMegabytes, ID: VolumeId, Type: OntapConfiguration.OntapVolumeType, Style: OntapConfiguration.SecurityStyle}' | sed -e 's/^/ /' >> {{ report_name }};
21+
done
22+
loop: "{{ fsxn_ids_per_region.stdout_lines }}"

Ansible/snapmirror_report/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The output of the report is a CSV file with the following columns:
1010

1111
## Requirements
1212
- Ansible 2.9 or later
13-
- AWS collection
13+
- AWS Ansible collection
1414

1515
## Installation
1616
There are three files used to create the report:

0 commit comments

Comments
 (0)