Skip to content

Commit 3cec50d

Browse files
authored
Merge pull request #202 from NetApp/add_ansible_sample
Add ansible samples
2 parents d25ff6d + 7585fb9 commit 3cec50d

File tree

11 files changed

+351
-0
lines changed

11 files changed

+351
-0
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
# Set the owner for all the individual samples, if the owner is known and they want to continue to maintain the sample:
66
/AI/GenAI-ChatBot-application-sample/ @cbenbass
77
/CloudFormation/deploy-fsx-ontap/ @kcantrel
8+
/Ansible/fsx_inventory_report/ @kcantrel
9+
/Ansible/snapmirror_report/ @kcantrel
810
/EKS/FSxN-as-PVC-for-EKS/ @mickeysh
911
/Management-Utilities/auto_create_sm_relationships/ @kcantrel
1012
/Management-Utilities/auto_set_fsxn_auto_grow/ @kcantrel

.github/linters/.yaml-lint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
extends: default
33
rules:
44
line-length: disable
5+
comments-indentation: disable
56
trailing-spaces: disable
67
truthy: disable
78
braces:

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 on [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. The format of the report is as follows:
4+
```
5+
Region: <region_name>
6+
File System ID: <file-system-id-1>
7+
SVM ID: <svm-id-1-1>
8+
Volumes:
9+
<volume-id-1-1-1> <volume-type> <security-style> <volume-size-in-megabytes> <volume-name>
10+
<volume-id-1-1-2> <volume-type> <security-style> <volume-size-in-megabytes> <volume-name>
11+
SVM ID: <svm-id-1-2>
12+
Volumes:
13+
<volume-id-1-2-2> <volume-type> <security-style> <volume-size-in-megabytes> <volume-name>
14+
<volume-id-1-2-2> <volume-type> <security-style> <volume-size-in-megabytes> <volume-name>
15+
File System ID: <file-system-id-2>
16+
SVM ID: <svm-id-2-1>
17+
Volumes:
18+
<volume-id-2-1-1> <volume-type> <security-style> <volume-size-in-megabytes> <volume-name>
19+
<volume-id-2-1-2> <volume-type> <security-style> <volume-size-in-megabytes> <volume-name>
20+
SVM ID: <svm-id-2-2>
21+
Volumes:
22+
<volume-id-2-2-1> <volume-type> <security-style> <volume-size-in-megabytes> <volume-name>
23+
<volume-id-2-2-2> <volume-type> <security-style> <volume-size-in-megabytes> <volume-name>
24+
```
25+
Where:
26+
- \<volume-size-in-megabytes> is the provisioned size of the volume in megabytes.
27+
- \<security-style> is the security style of the volume (e.g. UNIX, NTFS).
28+
- \<volume-type> is the type of the volume (e.g. RW, DP).
29+
30+
## Requirements
31+
- jq - A lightweight and flexible command-line JSON processor. Installation instructions can be found [here](https://jqlang.github.io/jq/download/)
32+
- Ansible 2.9 or later. Installation instructions can be found [here](https://docs.ansible.com/ansible/latest/installation_guide/index.html)
33+
- AWS Ansible collection. This should be included with the base installation of Ansible.
34+
35+
## Installation
36+
There are three files used to create the report:
37+
- `generate_report.yaml`: The Ansible playbook that generates the report.
38+
- `processs_region.yaml`: A collection of tasks that will process all the FSxNs in a region.
39+
- `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.
40+
41+
## Configuration
42+
There are a variable that can be changed at the top of the `generate_report.yaml` file:
43+
- report\_name - Sets the file path of the report that will be generated.
44+
45+
Since this script leverages the AWS Ansible collection as well as the `aws` cli, you will need to provide authentication credentials for them.
46+
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).
47+
48+
## Usage
49+
To generate the report copy the three files mentioned above and run the following command:
50+
```bash
51+
ansible-playbook generate_report.yaml
52+
```
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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
# This Ansible playbook generates an inventory report for all the FSXNs
3+
# in all the AWS regions for the account that it is running under.
4+
#################################################################################
5+
---
6+
- vars:
7+
report_name: output.txt
8+
#################################################################################
9+
#
10+
# Don't change anything below this line.
11+
#
12+
#################################################################################
13+
fsxn_regions: []
14+
opted_in_regions: []
15+
16+
name: Playbook to generate an inventory report on all the FSxNs.
17+
hosts: localhost
18+
collections:
19+
- amazon.aws
20+
gather_facts: false
21+
22+
tasks:
23+
- name: Make sure the report file is empty.
24+
ansible.builtin.shell:
25+
cmd: echo "" > {{ report_name }}
26+
27+
- name: Get all the regions that support FSxN that are opted into.
28+
include_tasks: get_fsxn_regions.yaml
29+
30+
- name: Generate the report for all the FSxNs.
31+
include_tasks: process_region.yaml
32+
loop: "{{ fsxn_regions }}"
33+
loop_control:
34+
loop_var: region
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# These tasks are used to set a variable named 'fsnx_regions' that contains a
3+
# list of regions that support FSxN and are opted-in.
4+
################################################################################
5+
- name: Get all the opted-in regions
6+
amazon.aws.aws_region_info:
7+
register: region_info
8+
9+
- name: Get region names
10+
set_fact:
11+
enabled_regions: "{{ region_info.regions | map(attribute='region_name') | list }}"
12+
13+
- name: Get the capabilities of all regions
14+
set_fact:
15+
regions_capabilities: "{{ lookup('ansible.builtin.url', 'https://api.regional-table.region-services.aws.a2z.com/index.json', split_lines=false) }}"
16+
17+
- name: Filter regions that support FSxN and are opted-in
18+
set_fact:
19+
fsxn_regions: >-
20+
{{
21+
regions_capabilities.prices
22+
| selectattr("attributes.aws:serviceName", "equalto", "Amazon FSx for NetApp ONTAP")
23+
| selectattr("attributes.aws:region", "in", enabled_regions)
24+
| map(attribute="attributes.aws:region")
25+
| list
26+
}}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Since Ansible can't handle nested loops, this is a block of tasked that is
3+
# run for each region. It assume that the calling playbook used 'region' as
4+
# its loop variable.
5+
################################################################################
6+
---
7+
- name: Get all the FSxNs for the specified region.
8+
ansible.builtin.shell:
9+
cmd: aws fsx describe-file-systems --region {{ region }} --query 'FileSystems[*].{FileSystemId:FileSystemId}' --output text | sed -e '/^$/d'
10+
register: fsxn_ids_per_region
11+
12+
- name: Get all the SVMs and volumes for each FSxN.
13+
ansible.builtin.shell:
14+
cmd: |
15+
echo "Region: {{ region }}" >> {{ report_name }};
16+
fs={{ item }};
17+
echo " File System ID: ${fs}" >> {{ report_name }};
18+
svms=$(aws fsx describe-storage-virtual-machines --filters Name=file-system-id,Values=${fs} --region {{ region }} --output=text --query 'StorageVirtualMachines[*].StorageVirtualMachineId');
19+
for svm in $svms; do
20+
echo " SVM ID: ${svm}" >> {{ report_name }};
21+
echo " Volume IDs:" >> {{ report_name }};
22+
aws fsx describe-volumes --filters Name=storage-virtual-machine-id,Values=${svm} --region {{ region }} --output=json --query 'Volumes[*].{Size: OntapConfiguration.SizeInMegabytes, ID: VolumeId, Name: Name, Type: OntapConfiguration.OntapVolumeType, Style: OntapConfiguration.SecurityStyle}' | jq -r '.[] | " \(.ID) \(.Type) \(.Style) \(.Size) \(.Name)"' >> {{ report_name }};
23+
done
24+
loop: "{{ fsxn_ids_per_region.stdout_lines }}"
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Ansible SnapMirror Report
2+
This Ansible playbook generates a report of all the FSx for ONTAP SnapMirror relationships within an AWS account.
3+
The output of the report is a CSV file with the following columns:
4+
- File System ID
5+
- Source Path (svm:volume)
6+
- Destination Path (svm:volume)
7+
- State (e.g. snapmirrored, broken-off)
8+
- Healthy (true or false)
9+
- lag\_time (in "P#DT#H#M#S" format. See below for an explanation)
10+
11+
The lag\_time format is an ASCII string that always starts with the letter 'P' and if the lag time is more than 24 hours it is followed by
12+
a number and the letter 'D'. The number represents the number days. The next character is always a 'T' and is followed by
13+
number/letter pairs, where the letter is either an 'H', 'M', or 'S'. If the letter is 'H' then the number before it represents
14+
the number of hours. If the letter is 'M' then the number before it represents the number of minutes. If the letter is 'S' then
15+
the number before it represents the number of seconds. For example, 'P1DT2H3M4S' represents 1 day, 2 hours, 3 minutes, and 4 seconds.
16+
17+
## Requirements
18+
- jq - A lightweight and flexible command-line JSON processor. Installation instructions can be found [here](https://jqlang.github.io/jq/download/)
19+
- Ansible 2.9 or later. Installation instructions can be found [here](https://docs.ansible.com/ansible/latest/installation_guide/index.html)
20+
- AWS Ansible collection. This should be included with the base installation of Ansible.
21+
- AWS secret(s) with the credentials necessary to run SnapMirror ONTAP APIs against the FSx for ONTAP file systems. The required format of the secret is described below.
22+
23+
## Installation
24+
There are three files used to create the report:
25+
- `generate_report.yaml`: The Ansible playbook that generates the report.
26+
- `processs_region.yaml`: A collection of tasks that will process all the FSxNs in a region.
27+
- `get_all_fsxn_regions.yaml`: A collection of tasks that retrieves all the regions, that are enabled for the account, where FSx for ONTAP is available.
28+
29+
You will also need to create a file named (by default) `secrets_list.csv` that list the secret name for each FSx file systems.
30+
The format of the file should be:
31+
```
32+
file_system_id,secret_name
33+
```
34+
:warning: **NOTE:** Do not add any spaces before or after the file\_system\_id or secret\_name.
35+
36+
Each secret should have two `keys`:
37+
| Key | Value |
38+
| --- | --- |
39+
| `username` | The username to use to authenticate with the FSx for ONTAP file system. |
40+
| `password` | The password to use to authenticate with the FSx for ONTAP file system. |
41+
42+
## Configuration
43+
There are a few variables that can be changed at the top of the `generate_report.yaml` file:
44+
- report\_name - Sets the file path of the report that will be generated.
45+
- secrets\_list\_file - Sets the file path of the file that contains the list of FSx file systems and their secrets. See above for more information.
46+
- secrets\_region - Set the region where the secrets are stored.
47+
48+
Since this script leverages the AWS Ansible collection as well as the `aws` cli, you will need to provide authentication credentials for them.
49+
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).
50+
51+
## Usage
52+
To generate the report, run the following command:
53+
```bash
54+
ansible-playbook generate_report.yaml
55+
```
56+
After a successful run, the report will be stored in the file specified by the `report_name` variable.
57+
58+
## Author Information
59+
60+
This repository is maintained by the contributors listed on [GitHub](https://github.com/NetApp/FSx-ONTAP-samples-scripts/graphs/contributors).
61+
62+
## License
63+
64+
Licensed under the Apache License, Version 2.0 (the "License").
65+
66+
You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0).
67+
68+
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.
69+
70+
See the License for the specific language governing permissions and limitations under the License.
71+
72+
© 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 SnapMirrorreport 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_list.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+
#
2+
# These tasks are used to set a variable named 'fsnx_regions' that contains a
3+
# list of regions that support FSxN and are opted-in.
4+
################################################################################
5+
- name: Get all the opted-in regions
6+
amazon.aws.aws_region_info:
7+
register: region_info
8+
9+
- name: Get region names
10+
set_fact:
11+
enabled_regions: "{{ region_info.regions | map(attribute='region_name') | list }}"
12+
13+
- name: Get the capabilities of all regions
14+
set_fact:
15+
regions_capabilities: "{{ lookup('ansible.builtin.url', 'https://api.regional-table.region-services.aws.a2z.com/index.json', split_lines=false) }}"
16+
17+
- name: Filter regions that support FSxN and are opted-in
18+
set_fact:
19+
fsxn_regions: >-
20+
{{
21+
regions_capabilities.prices
22+
| selectattr("attributes.aws:serviceName", "equalto", "Amazon FSx for NetApp ONTAP")
23+
| selectattr("attributes.aws:region", "in", enabled_regions)
24+
| map(attribute="attributes.aws:region")
25+
| list
26+
}}

0 commit comments

Comments
 (0)