Skip to content

Commit 624309a

Browse files
committed
Updated it to use the ONTAP Ansible collection as opposed to invoking 'curl' commands to get the SnapMirror information.
1 parent 06d3b9a commit 624309a

File tree

4 files changed

+84
-36
lines changed

4 files changed

+84
-36
lines changed

Infrastructure_as_Code/Ansible/snapmirror_report/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ the number of hours. If the letter is 'M' then the number before it represents t
1515
the number before it represents the number of seconds. For example, 'P1DT2H3M4S' represents 1 day, 2 hours, 3 minutes, and 4 seconds.
1616

1717
## Requirements
18-
- jq - A lightweight and flexible command-line JSON processor. Installation instructions can be found [here](https://jqlang.github.io/jq/download/)
1918
- 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.
19+
- NetApp ONTAP Ansible collection.
20+
- AWS Ansible collection.
2121
- 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+
- The `aws` cli installed and configured. Installation instructions can be found [here](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html).
23+
- A file with a list of the FSx for ONTAP file systems and their corresponding secrets. The format of the file is described below.
2224

2325
## Installation
2426
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.
27+
- `generate_report.yaml`: The main Ansible playbook that generates the report.
28+
- `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 also available.
29+
- `processs_region.yaml`: A collection of tasks that will process all the FSxNs within a region.
2830

2931
You will also need to create a file named (by default) `secrets_list.csv` that list the secret name for each FSx file systems.
3032
The format of the file should be:

Infrastructure_as_Code/Ansible/snapmirror_report/generate_report.yaml

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,40 @@
1+
#################################################################################
2+
# This Ansible playbook generates a csv file that contains the following
3+
# information for each SnapMirror relationship in all of the FSxNs in all
4+
# of the AWS regions:
5+
#
6+
# FilesystemID
7+
# source
8+
# destination
9+
# state
10+
# healthy
11+
# lag_time
12+
#
13+
# This playbook is dependent on the 'aws' cli being installed and configured
14+
# (i.e. authenticated.) It is need to list all the FSxNs within a region
15+
# since there isn't an amazon.aws.fsx_info module that can do that.
16+
#
17+
# It is also dependent on a csv file that should contain the AWS
18+
# secret for each FSxNs. The format of the secrets.csv file is as follows:
19+
#
20+
# FilesystemID,serect_name
21+
#
22+
# Each secret should have two keys 'username' and 'password'.
23+
#
24+
# The name of the file is set vai the "secrets_list_file" variable below.
25+
#
26+
# It is assumed that all secrets will be in the same region, which is defined
27+
# in the secrets_region variable below.
28+
#
29+
# The output of the playbook is a CSV file that contains the following columns:
30+
#
31+
# fs,source,destination,state,healthy,lag_time
132
#
2-
# This Ansible playbook generates a SnapMirrorreport for all the
3-
# SnapMirror relationships, in all the FSxNs, in all regions,
433
#################################################################################
534
---
635
- vars:
736
report_name: output.csv
8-
secrets_list_file: secrets_list.csv
37+
secrets_list_file: secrets.csv
938
secrets_region: us-west-2
1039
#################################################################################
1140
#
@@ -19,14 +48,15 @@
1948
hosts: localhost
2049
collections:
2150
- amazon.aws
51+
- netapp.ontap
2252
gather_facts: false
2353

2454
tasks:
2555
- name: Delete previous report while adding the header line.
2656
ansible.builtin.shell:
2757
cmd: echo fs,source,destination,state,healthy,lag_time > {{ report_name }}
2858

29-
- name: Get all the regions that support FSxN that I am opted into.
59+
- name: Get all the regions that support FSxN that are opted into.
3060
include_tasks: get_fsxn_regions.yaml
3161

3262
- name: Generate the report for all the FSxNs.

Infrastructure_as_Code/Ansible/snapmirror_report/get_fsxn_regions.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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.
41
################################################################################
2+
# This Ansiable playbook it used to return all of the regions that support FSxN
3+
# and are opted-in. It stores the list of regions in the fsxn_regions variable.
4+
################################################################################
5+
#
56
- name: Get all the opted-in regions
67
amazon.aws.aws_region_info:
78
register: region_info
Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,51 @@
1+
################################################################################
2+
# Since Ansible can't handle nested loops, this is a block of tasks that is run
3+
# for each region. It assumes that the calling playbook used 'region' as its
4+
# loop variable.
15
#
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 its loop variable.
4-
#################################################################################
6+
# It gathers all the snapmirror information for all the FSxNs with a region
7+
# that a secret is defined for in the secrets.csv file. Once it has gathered
8+
# all the information, it writes it to an output.csv file in the format:
9+
#
10+
# source_cluster::source_path,destination_cluster::destination_path,state,healthy,lag_time
11+
#
12+
################################################################################
513
---
14+
- name:
15+
debug:
16+
msg: "Processing region {{ region }}"
17+
618
- name: Get all the FSxNs for the specified region.
719
ansible.builtin.shell:
8-
cmd: aws fsx describe-file-systems --region {{ region }} --query 'FileSystems[*].{FileSystemId:FileSystemId}' --output text | sed -e '/^$/d'
20+
cmd: aws fsx describe-file-systems --region {{ region }} --query 'FileSystems[*].{ID:FileSystemId,IP:OntapConfiguration.Endpoints.Management.IpAddresses[0]}' --output text | sed -e '/^$/d'
921
register: fsxn_ids_per_region
1022

1123
- name: Get the SnapMirror relationships for each FSxN.
1224
when: secret != 'n/a'
13-
ansible.builtin.shell:
14-
cmd: |
15-
fs={{ item }};
16-
username="{{ lookup('amazon.aws.aws_secret', '{{ secret }}.username', region=secrets_region, nested=true, on_missing='skip') }}";
17-
password="{{ lookup('amazon.aws.aws_secret', '{{ secret }}.password', region=secrets_region, nested=true, on_missing='skip') }}";
18-
if [ "$username" = '[]' -o "$password" = '[]' ]; then
19-
echo "Missing secret for file system $fs" 1>&2;
20-
exit 0;
21-
fi;
22-
ip=$(aws fsx describe-file-systems --region {{ region }} --file-system-ids $fs --query 'FileSystems[0].OntapConfiguration.Endpoints.Management.IpAddresses[0]' --output=text);
23-
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)"'
25+
netapp.ontap.na_ontap_rest_info:
26+
username: "{{ lookup('amazon.aws.aws_secret', '{{ secret }}.username', region=secrets_region, nested=true, on_missing='skip') }}"
27+
password: "{{ lookup('amazon.aws.aws_secret', '{{ secret }}.password', region=secrets_region, nested=true, on_missing='skip') }}"
28+
hostname: "{{ item.split('\t')[1] }}"
29+
validate_certs: false
30+
fields:
31+
- source
32+
- destination
33+
- healthy
34+
- lag_time
35+
- state
36+
gather_subset:
37+
- snapmirror/relationships
2438
loop: "{{ fsxn_ids_per_region.stdout_lines }}"
2539
register: snapmirror_relationships
2640
vars:
27-
secret: "{{ lookup('ansible.builtin.csvfile', item, file=secrets_list_file, delimiter=',', default='n/a') }}"
41+
secret: "{{ lookup('ansible.builtin.csvfile', item.split('\t')[0], file=secrets_list_file, delimiter=',', default='n/a') }}"
2842

29-
- name: Write the SnapMirror relationships to a file.
30-
when: item.stdout is defined
31-
ansible.builtin.shell:
32-
cmd: |
33-
if [ "{{ item.stdout }}" != "" ]; then
34-
echo "{{ item.stdout }}" >> {{ report_name }};
35-
fi
36-
loop: "{{ snapmirror_relationships.results }}"
43+
- name: Write the SnapMirror relationship infor to a file.
44+
ansible.builtin.lineinfile:
45+
insertafter: EOF
46+
path: output.csv
47+
line: "{{ item.source.cluster.name }}::{{ item.source.path }},{{ item.destination.cluster.name }}::{{ item.destination.path }},{{ item.state }},{{ item.healthy }},{{ lag_time }}"
48+
loop: "{{ snapmirror_relationships.results[0].ontap_info['snapmirror/relationships'].records }}"
49+
when: snapmirror_relationships.results | length > 0 and snapmirror_relationships.results[0].ontap_info is defined
50+
vars:
51+
lag_time: "{{ item.lag_time if item.lag_time is defined else 'n/a' }}"

0 commit comments

Comments
 (0)