|
| 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. |
1 | 5 | # |
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 | +################################################################################ |
5 | 13 | --- |
| 14 | +- name: |
| 15 | + debug: |
| 16 | + msg: "Processing region {{ region }}" |
| 17 | + |
6 | 18 | - name: Get all the FSxNs for the specified region. |
7 | 19 | 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' |
9 | 21 | register: fsxn_ids_per_region |
10 | 22 |
|
11 | 23 | - name: Get the SnapMirror relationships for each FSxN. |
12 | 24 | 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 |
24 | 38 | loop: "{{ fsxn_ids_per_region.stdout_lines }}" |
25 | 39 | register: snapmirror_relationships |
26 | 40 | 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') }}" |
28 | 42 |
|
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