Skip to content

Commit 61b8ce6

Browse files
committed
Initial Version
1 parent 2ccef16 commit 61b8ce6

File tree

4 files changed

+152
-0
lines changed

4 files changed

+152
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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)
10+
11+
## Requirements
12+
- Ansible 2.9 or later
13+
- AWS collection
14+
15+
## Installation
16+
There are three files used to create the report:
17+
- `generate_report.yaml`: The Ansible playbook that generates the report.
18+
- `processs_region.yaml`: A collection of tasks that will process all the FSxNs in a region.
19+
- `get_all_fsxn_regions.yaml`: A colleciton of tasks that retrieves all the regions, that are enabled for the account, where FSx for ONTAP is available.
20+
21+
You will also need to create a file named (by default) `secrets_list.csv` that list the secret name for each FSx file system.
22+
The format of the file should be:
23+
```
24+
file_system_id,secret_name
25+
```
26+
You should have all four of these files in a single directory.
27+
28+
## Configuration
29+
There are a few varaibles that can be changed at the top of the `generate_report.yaml` file:
30+
- report\_name - Sets the file path of the report that will be generated.
31+
- secrets\_list\_file - Sets the file path of the file that contains the list of FSx file systems and their secrets.
32+
- secrets\_region - Set the region where the secrets are stored.
33+
34+
## Usage
35+
To generate the report, run the following command:
36+
```bash
37+
ansible-playbook generate_report.yaml
38+
```
39+
After a succesful run, the report will be saved to the file path specified in the `report_name` variable.
40+
41+
## Author Information
42+
43+
This repository is maintained by the contributors listed on [GitHub](https://github.com/NetApp/FSx-ONTAP-samples-scripts/graphs/contributors).
44+
45+
## License
46+
47+
Licensed under the Apache License, Version 2.0 (the "License").
48+
49+
You may obtain a copy of the License at [apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0).
50+
51+
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.
52+
53+
See the License for the specific language governing permissions and limitations under the License.
54+
55+
© 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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 the SnapMirror relationships for each FSxN.
11+
when: secret != 'n/a'
12+
ansible.builtin.shell:
13+
cmd: |
14+
fs={{ item }};
15+
username="{{ lookup('amazon.aws.aws_secret', '{{ secret }}.username', region=secrets_region, nested=true, on_missing='skip') }}";
16+
password="{{ lookup('amazon.aws.aws_secret', '{{ secret }}.password', region=secrets_region, nested=true, on_missing='skip') }}";
17+
if [ "$username" = '[]' -o "$password" = '[]' ]; then
18+
echo "Missing secret for file system $fs" 1>&2;
19+
exit 0;
20+
fi;
21+
ip=$(aws fsx describe-file-systems --region {{ region }} --file-system-ids $fs --query 'FileSystems[0].OntapConfiguration.Endpoints.Management.IpAddresses[0]' --output=text);
22+
curl -s -u "${username}:${password}" -k https://$ip/api/snapmirror/relationships?fields=source,destination,lag_time,state,healthy | jq -r '.records[] | "'${fs}',\(.source.path),\(.destination.path),\(.state),\(.healthy),\(.lag_time)"'
23+
loop: "{{ fsxn_ids_per_region.stdout_lines }}"
24+
register: snapmirror_relationships
25+
vars:
26+
secret: "{{ lookup('ansible.builtin.csvfile', item, file=secrets_list_file, delimiter=',', default='n/a') }}"
27+
28+
- name: Write the SnapMirror relationships to a file.
29+
when: item.stdout is defined
30+
ansible.builtin.shell:
31+
cmd: |
32+
if [ "{{ item.stdout }}" != "" ]; then
33+
echo "{{ item.stdout }}" >> {{ report_name }};
34+
fi
35+
loop: "{{ snapmirror_relationships.results }}"

0 commit comments

Comments
 (0)