| 1 |
--- |
| 2 |
- name: IBM FlashSystem Log and Dump Collection |
| 3 |
hosts: localhost |
| 4 |
connection: local |
| 5 |
gather_facts: false |
| 6 |
vars_files: |
| 7 |
- inventory.ini |
| 8 |
vars: |
| 9 |
logpath: "{{ log_path | default('/tmp/log_collection.log') }}" |
| 10 |
|
| 11 |
tasks: |
| 12 |
- name: Remove cluster key from known_hosts |
| 13 |
ansible.builtin.command: ssh-keygen -R "{{ clustername }}" |
| 14 |
ignore_errors: true |
| 15 |
register: remove_service_key |
| 16 |
changed_when: remove_service_key.rc != 0 |
| 17 |
|
| 18 |
- name: Fetch system details for cluster |
| 19 |
register: system_info |
| 20 |
ibm.storage_virtualize.ibm_svc_info: |
| 21 |
clustername: "{{ clustername }}" |
| 22 |
username: "{{ cluster_username }}" |
| 23 |
password: "{{ cluster_password }}" |
| 24 |
gather_subset: node |
| 25 |
log_path: "{{ logpath }}" |
| 26 |
|
| 27 |
- name: Take the snap |
| 28 |
ibm.storage_virtualize.ibm_svctask_command: |
| 29 |
command: "svc_snap a" |
| 30 |
clustername: "{{ clustername }}" |
| 31 |
username: "{{ cluster_username }}" |
| 32 |
password: "{{ cluster_password }}" |
| 33 |
log_path: "{{ logpath }}" |
| 34 |
|
| 35 |
- name: Prepare and trigger livedump on each node |
| 36 |
ibm.storage_virtualize.ibm_svctask_command: |
| 37 |
command: "preplivedump {{ item.name }} && triggerlivedump {{ item.name }}" |
| 38 |
clustername: "{{ clustername }}" |
| 39 |
username: "{{ cluster_username }}" |
| 40 |
password: "{{ cluster_password }}" |
| 41 |
log_path: "{{ logpath }}" |
| 42 |
loop: "{{ system_info.Node }}" |
| 43 |
loop_control: |
| 44 |
label: "{{ item.name }}" |
| 45 |
pause: 5 |
| 46 |
|
| 47 |
- name: Set current timestamp |
| 48 |
ansible.builtin.set_fact: |
| 49 |
timestamp: "{{ lookup('pipe', 'date +%Y%m%d_%H%M%S') }}" |
| 50 |
|
| 51 |
- name: Set log directory path |
| 52 |
ansible.builtin.set_fact: |
| 53 |
log_dir: "{{ lookup('env', 'HOME') }}/log_{{ clustername | replace('.', '_') }}_{{ timestamp }}" |
| 54 |
|
| 55 |
- name: Create log directory |
| 56 |
ansible.builtin.file: |
| 57 |
path: "{{ log_dir }}" |
| 58 |
state: directory |
| 59 |
mode: '0755' |
| 60 |
|
| 61 |
- name: Get list of dumps, snaps and node info from each node |
| 62 |
register: svcinfo_results |
| 63 |
ibm.storage_virtualize.ibm_svcinfo_command: |
| 64 |
command: "lsnodecanister {{ item.id }} && sainfo lsfiles {{ item.panel_name }} -prefix /dumps" |
| 65 |
clustername: "{{ clustername }}" |
| 66 |
username: "{{ cluster_username }}" |
| 67 |
password: "{{ cluster_password }}" |
| 68 |
log_path: "{{ logpath }}" |
| 69 |
loop: "{{ system_info.Node }}" |
| 70 |
loop_control: |
| 71 |
label: "{{ item.name }}" |
| 72 |
|
| 73 |
- name: Parse and store snap and livedump files |
| 74 |
ansible.builtin.set_fact: |
| 75 |
nodes_info: "{{ nodes_info | default({}) | combine({item.item.name: {'name': node_name, 'ip': node_ip, 'files': [snap] + livedumps}}) }}" |
| 76 |
vars: |
| 77 |
output_lines: "{{ item.stdout.splitlines() }}" |
| 78 |
node_name: "{{ output_lines | select('search', 'name') | list | first | split() | last | default('') }}" |
| 79 |
node_ip: "{{ output_lines | select('search', 'service_IP_address') | list | first | split() | last | default('') }}" |
| 80 |
snap: "{{ (output_lines | select('search', 'snap') | select('search', 'tgz') | reject('search', 'info') | list)[-3] | default('') }}" |
| 81 |
livedumps: "{{ (output_lines | select('search', 'livedump') | list)[-3:] }}" |
| 82 |
loop: "{{ svcinfo_results.results }}" |
| 83 |
loop_control: |
| 84 |
label: "{{ item.item.name }}" |
| 85 |
|
| 86 |
- name: Remove nodes key from known_hosts |
| 87 |
ansible.builtin.command: ssh-keygen -R "{{ item.ip }}" |
| 88 |
ignore_errors: true |
| 89 |
register: remove_service_key |
| 90 |
changed_when: remove_service_key.rc != 0 |
| 91 |
loop: "{{ nodes_info.values() | list }}" |
| 92 |
|
| 93 |
- name: Copy snap and dump files from each node to ansible controller |
| 94 |
ansible.builtin.expect: |
| 95 |
command: scp -O -o StrictHostKeyChecking=no -r {{ cluster_username }}@{{ item.0.ip }}:/dumps/{{ item.1 }} {{ log_dir }} |
| 96 |
responses: |
| 97 |
(?i)Are you sure you want to continue connecting (yes/no/[fingerprint])?: "yes\r\n" |
| 98 |
(?i)Password: "{{ cluster_password }}" |
| 99 |
timeout: null |
| 100 |
async: 3600 |
| 101 |
poll: 0 |
| 102 |
register: async_jobs |
| 103 |
loop: "{{ query('subelements', nodes_info.values() | list, 'files') }}" |
| 104 |
loop_control: |
| 105 |
label: "Copying {{ item.1 }} from {{ item.0.name }} ({{ item.0.ip }}) to {{ log_dir }}/{{ item.1 }}" |
| 106 |
pause: 5 |
| 107 |
|
| 108 |
- name: Wait for SCP to complete |
| 109 |
ansible.builtin.async_status: |
| 110 |
jid: "{{ item.ansible_job_id }}" |
| 111 |
register: job_result |
| 112 |
until: job_result is finished |
| 113 |
retries: 20 |
| 114 |
delay: 180 |
| 115 |
loop: "{{ async_jobs.results }}" |
| 116 |
|
| 117 |
- name: Display log path |
| 118 |
ansible.builtin.debug: |
| 119 |
msg: "All logs collected under the path: {{ log_dir }}" |