-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaerospike_support_case.yml
184 lines (179 loc) · 10.8 KB
/
aerospike_support_case.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
---
# code: language=ansible
# See https://github.com/lwillek/aerospike_support_case/blob/main/README.md
# BSD Zero Clause License
# For full license text see https://github.com/lwillek/aerospike_support_case/blob/main/LICENSE
# SPDX-License-Identifier: 0BSD
- name: "Ansible play which collects relevant information and attaches them to an existing Aerospike Support Case"
hosts: all
ignore_unreachable: true
any_errors_fatal: true
become: true
vars:
aerospike_support_ftp_host: asftp.aerospike.com
# yamllint disable-line rule:line-length
aerospike_support_ftp_host_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCHsI1UNHPQe59Mg7oOIly437NH+6RGNdRNg+z+KWMKLBQyQ4HzY1zKyJz0YDP67ZY4QmAONfLkDAM8VpTvhhtFzU2dCa6Miv8+OX4zJsSgwRKddDhE6MYyvDl897uGmi2clxtjRjtl1KUAUza5yQvcsVQRjdbBZ+73s9Rg6g87C+Fo/DG98wjYcZHXsvZUUNer++RMLo8PFvuY+vsD7yYs4MrdEjCHhbkgmHR8Py4Nnvs2q3JCHY9l7g5+S/wpO22z5PGJ6Ts7boxSRXMRCTxbIdHJTIHl69XHsDh7x+aS1tGHzpOziLmZMgsrqrDdkfJADoGDHgmoNw6t72K4sOTAmTSk9qqnKnEIeVxgaRKd/3xrbyiby4MjPVUAeKcysF9/NfF5//GcbRk9lc03OsbWTfBdj1O+x0nd0hSqFlYyqjo5i5P6vekFXkJmKtmLJhmlLg129TogQeef/vaHMxHulqHE+A+R+MKEoH+aJknyxirDriFshJ4RNl4yJJXk/g5xHPKW61RtaPkVqfZt57FoJ6amGwdypUfzNPrplT4kDtfGdimgRCNziAoKzLD3HI69+1xanC71lr6INylv9EdHGYd8pbO3OXY6KbRdejvI5BFT9F8m4q8X6phznBdUFlAHBWVlRYooPGUpQvJipx0CL6btkztEDCXN5wxY+YHMFQ==
aerospike_support_ftp_options: !unsafe '-o Port=2222'
domain_name: example.org # Set this to your domain.
provide_logfile: true # Set this to true in case you want to provide the aerospike.log file.
provide_collectinfo: true # Set this to true in case you want to provide the asadm collectinfo file.
ansible_debuginfo: false # Set this to true in case you want to see some Ansible play debug output.
vars_prompt:
- name: "aerospike_support_case"
prompt: Enter the Aerospike Support case
private: false
- name: "aerospike_support_ftp_username"
prompt: Enter your Aerospike FTP username for this Aerospike case
private: false
- name: "aerospike_support_ftp_password"
prompt: Enter your Aerospike FTP password for this Aerospike case
unsafe: true
private: true
tasks:
- name: "AEROSPIKE SUPPORT CASE | Ensure expect package is installed"
ansible.builtin.package:
name: expect
state: present
when: provide_logfile | bool or provide_collectinfo | bool
- name: "AEROSPIKE SUPPORT CASE | Ensure temporary known_hosts file is created"
ansible.builtin.tempfile:
state: file
prefix: aerospike_known_hosts
register: known_hosts
when: provide_logfile | bool or provide_collectinfo | bool
- name: "AEROSPIKE SUPPORT CASE | Ensure temporary known_hosts file is populated"
ansible.builtin.copy:
content: "{{ aerospike_support_ftp_host }} {{ aerospike_support_ftp_host_key }}\n"
dest: "{{ known_hosts.path }}"
owner: root
group: root
mode: '0600'
when: provide_logfile | bool or provide_collectinfo | bool
- name: "AEROSPIKE SUPPORT CASE | adasm"
block:
- name: "AEROSPIKE SUPPORT CASE | Execute adasm collectinfo"
ansible.builtin.command: asadm -e collectinfo
changed_when: true
when: provide_collectinfo | bool
rescue:
- name: "AEROSPIKE SUPPORT CASE | Rescue | Skip adasm collectinfo from now on"
ansible.builtin.debug:
msg: "The adasm program could not be found - skipping"
register: adasm_not_found
when: provide_collectinfo | bool
- name: "AEROSPIKE SUPPORT CASE | Locate the most recent collect_info file"
ansible.builtin.shell: 'set -o pipefail && ls -1r /tmp/collect_info_*tgz | head -1'
args:
executable: bash
register: collect_info__file_name
changed_when: true
when: provide_collectinfo | bool and adasm_not_found is not defined
- name: "AEROSPIKE SUPPORT CASE | Output facts - Debug information - collectinfo"
ansible.builtin.debug:
msg:
- "Aerospike FQDN node name: {{ ansible_hostname }}.{{ domain_name }}"
- "Aerospike Case: {{ aerospike_support_case }}"
- "Aerospike FTP host: {{ aerospike_support_ftp_host }}"
- "FTP Username: {{ aerospike_support_ftp_username }}"
- "collectinfo most recent file name: {{ collect_info__file_name.stdout }} ({{ collect_info__file_name.stdout | regex_replace('^.*/(.*)$', '\\1') }})"
- "provide_collectinfo FTP command: scp -o UserKnownHostsFile={{ known_hosts.path }} -o StrictHostKeyChecking=yes {{ aerospike_support_ftp_options }} {{ collect_info__file_name.stdout | default('undefined', true) }} {{ aerospike_support_ftp_username }}@{{ aerospike_support_ftp_host }}:/Cases/{{ aerospike_support_case }}/{{ ansible_hostname }}.{{ domain_name }}__{{ collect_info__file_name.stdout | regex_replace('^.*/(.*)$', '\\1') }}" # yamllint disable-line rule:line-length
when: provide_collectinfo | bool and ansible_debuginfo | bool and adasm_not_found is not defined
- name: "AEROSPIKE SUPPORT CASE | Upload collect_info"
block:
- name: "AEROSPIKE SUPPORT CASE | Upload most recent collect_info file to {{ aerospike_support_ftp_host }}"
ansible.builtin.shell: |
set timeout 60
spawn scp {{ ftp_options }} {{ aerospike_support_ftp_options }} {{ source }} {{ destination }}
expect "Password:"
send "{{ aerospike_support_ftp_password }}\n"
expect eof
args:
executable: expect
vars:
source: "{{ collect_info__file_name.stdout }}"
destination: "{{ aerospike_support_ftp_username }}@{{ aerospike_support_ftp_host }}:/Cases/{{ aerospike_support_case }}/{{ ansible_hostname }}.{{ domain_name }}__{{ collect_info__file_name.stdout | regex_replace('^.*/(.*)$', '\\1') }}" # yamllint disable-line rule:line-length
ftp_options: '-o UserKnownHostsFile={{ known_hosts.path }} -o StrictHostKeyChecking=yes'
changed_when: true
when: provide_collectinfo | bool and adasm_not_found is not defined
rescue:
- name: "AEROSPIKE SUPPORT CASE | Rescue | upload failed"
ansible.builtin.debug:
msg: "The collect_info file upload failed - skipping"
register: upload_failed
- name: "AEROSPIKE SUPPORT CASE | aerospike.log"
block:
- name: "AEROSPIKE SUPPORT CASE | Register aerospike.log timestamp"
ansible.builtin.command: 'date +"%Y%m%d_%H%M%S"'
register: timestamp
changed_when: true
when: provide_logfile | bool
- name: "AEROSPIKE SUPPORT CASE | Compress aerospike.log file"
ansible.legacy.archive:
path: /var/log/aerospike/aerospike.log
dest: "/tmp/aerospike_log_{{ timestamp.stdout }}.tgz"
owner: root
group: root
mode: "0600"
when: provide_logfile | bool
rescue:
- name: "AEROSPIKE SUPPORT CASE | Rescue | Skip aerospike.log from now on"
ansible.builtin.debug:
msg: "No aerospike.log file could not be found - skipping"
register: logfile_not_found
when: provide_collectinfo | bool
- name: "AEROSPIKE SUPPORT CASE | Locate the most recent compressed aerospike.log file"
ansible.builtin.shell: 'set -o pipefail && ls -1r /tmp/aerospike_log_*tgz | head -1'
args:
executable: bash
register: aerospike_log__file_name
changed_when: true
when: provide_logfile | bool and logfile_not_found is not defined
- name: "AEROSPIKE SUPPORT CASE | Output facts - Debug information - aerospike.log"
ansible.builtin.debug:
msg:
- "Aerospike host name: {{ ansible_hostname }}.{{ domain_name }}"
- "Aerospike Case: {{ aerospike_support_case }}"
- "Aerospike FTP host: {{ aerospike_support_ftp_host }}"
- "FTP Username: {{ aerospike_support_ftp_username }}"
- "Compressed aerospike.log most recent file name: {{ aerospike_log__file_name.stdout | default('undefined', true) }} ({{ aerospike_log__file_name.stdout | default('undefined', true) | regex_replace('^.*/(.*)$', '\\1') }})" # yamllint disable-line rule:line-length
- "provide_logfile ftp command: scp -o UserKnownHostsFile={{ known_hosts.path }} -o StrictHostKeyChecking=yes {{ aerospike_support_ftp_options }} {{ aerospike_log__file_name.stdout | default('undefined', true) }} {{ aerospike_support_ftp_username }}@{{ aerospike_support_ftp_host }}:/Cases/{{ aerospike_support_case }}/{{ ansible_hostname }}.{{ domain_name }}__{{ aerospike_log__file_name.stdout | regex_replace('^.*/(.*)$', '\\1') }}" # yamllint disable-line rule:line-length
when: provide_logfile | bool and ansible_debuginfo | bool and logfile_not_found is not defined
- name: "AEROSPIKE SUPPORT CASE | Upload aerospike.log"
block:
- name: "AEROSPIKE SUPPORT CASE | Upload most recent aerospike.log file to {{ aerospike_support_ftp_host }}"
ansible.builtin.shell: |
set timeout 60
spawn scp {{ ftp_options }} {{ aerospike_support_ftp_options }} {{ source }} {{ destination }}
expect "Password:"
send "{{ aerospike_support_ftp_password }}\n"
expect eof
args:
executable: expect
vars:
source: "{{ aerospike_log__file_name.stdout }}"
destination: "{{ aerospike_support_ftp_username }}@{{ aerospike_support_ftp_host }}:/Cases/{{ aerospike_support_case }}/{{ ansible_hostname }}.{{ domain_name }}__{{ aerospike_log__file_name.stdout | regex_replace('^.*/(.*)$', '\\1') }}" # yamllint disable-line rule:line-length
ftp_options: '-o UserKnownHostsFile={{ known_hosts.path }} -o StrictHostKeyChecking=yes'
changed_when: true
when: provide_logfile | bool and logfile_not_found is not defined
rescue:
- name: "AEROSPIKE SUPPORT CASE | Rescue | upload failed"
ansible.builtin.debug:
msg: "The aerospike.log file upload failed - skipping"
register: upload_failed
- name: "AEROSPIKE SUPPORT CASE | Ensure temporary known_hosts file is removed"
ansible.builtin.file:
path: "{{ known_hosts.path }}"
state: absent
when: known_hosts.path is defined
- name: "AEROSPIKE SUPPORT CASE | Operator's information on next steps"
ansible.builtin.debug:
msg:
- "Log in now with your FTP credentials to https://{{ aerospike_support_ftp_host }}/#/Cases/{{ aerospike_support_case }}/"
- "Check if all expected files have been uploaded to Aerospike."
- "Update the case now with further informations."
when: provide_logfile | bool or provide_collectinfo | bool
- name: "AEROSPIKE SUPPORT CASE | Upload failed notification"
ansible.builtin.debug:
msg:
- "At least one opload failed!"
when: upload_failed is defined