|
| 1 | +--- |
| 2 | +- name: Cleanup |
| 3 | + hosts: all |
| 4 | + become: true |
| 5 | + become_method: sudo |
| 6 | + vars: |
| 7 | + WORKSPACE_VAR: "{{ lookup('env', 'WORKSPACE_VAR') }}" |
| 8 | + tasks: |
| 9 | + - name: PRINT WORKSPACE_VAR |
| 10 | + debug: |
| 11 | + msg: "WORKSPACE_VAR: {{ WORKSPACE_VAR }}" |
| 12 | + |
| 13 | + - name: Check if mysqld.log exists |
| 14 | + stat: |
| 15 | + path: /var/log/mysqld.log |
| 16 | + register: mysqld_log |
| 17 | + |
| 18 | + - name: Check if mysql error log exists |
| 19 | + stat: |
| 20 | + path: /var/log/mysql/error.log |
| 21 | + register: mysql_error_log |
| 22 | + |
| 23 | + - name: Create a temporary directory for zipping logs |
| 24 | + file: |
| 25 | + path: /var/tmp/mysql_logs |
| 26 | + state: directory |
| 27 | + mode: '0755' |
| 28 | + when: |
| 29 | + - mysqld_log.stat.exists or mysql_error_log.stat.exists |
| 30 | + |
| 31 | + - name: Copy mysqld.log to temporary directory if it exists |
| 32 | + shell: cp /var/log/mysqld.log /var/tmp/mysql_logs/mysqld.log |
| 33 | + when: mysqld_log.stat.exists |
| 34 | + |
| 35 | + - name: Copy mysql error log to temporary directory if it exists |
| 36 | + shell: cp /var/log/mysql/error.log /var/tmp/mysql_logs/error.log |
| 37 | + when: mysql_error_log.stat.exists |
| 38 | + |
| 39 | + - name: Zip the log files if any exist |
| 40 | + archive: |
| 41 | + path: /var/tmp/mysql_logs |
| 42 | + dest: /var/tmp/mysql_logs.zip |
| 43 | + format: zip |
| 44 | + when: |
| 45 | + - mysqld_log.stat.exists or mysql_error_log.stat.exists |
| 46 | +## |
| 47 | + |
| 48 | + - name: Get the arch value from /etc/os-release |
| 49 | + shell: uname -m |
| 50 | + register: arch_output |
| 51 | + |
| 52 | + - name: Replace spaces with dashes in arch_output |
| 53 | + set_fact: |
| 54 | + arch_output: "{{ arch_output.stdout | trim }}" |
| 55 | + |
| 56 | +## |
| 57 | + - name: Get the PRETTY_NAME value from /etc/os-release |
| 58 | + shell: | |
| 59 | + grep '^PRETTY_NAME=' /etc/os-release | cut -d'=' -f2 | tr -d '"' |
| 60 | + register: pretty_name_output |
| 61 | + |
| 62 | + - name: Replace spaces with dashes in PRETTY_NAME |
| 63 | + set_fact: |
| 64 | + os_id: "{{ pretty_name_output.stdout | replace(' ', '-') | trim }}" |
| 65 | + |
| 66 | + - name: Debug the arch_output |
| 67 | + debug: |
| 68 | + msg: "The arch_output is {{ arch_output }}" |
| 69 | + |
| 70 | + - name: Debug the OS ID |
| 71 | + debug: |
| 72 | + msg: "The OS ID is {{ os_id }}" |
| 73 | + |
| 74 | + - name: Fetch the logs archive on localhost |
| 75 | + fetch: |
| 76 | + src: /var/tmp/mysql_logs.zip |
| 77 | + dest: "/{{ WORKSPACE_VAR }}/{{ ansible_hostname }}_{{ os_id }}_{{ arch_output }}_mysql_logs.zip" |
| 78 | + flat: yes |
| 79 | + become: true |
| 80 | + |
| 81 | + - name: Debug the fetch task status on localhost |
| 82 | + command: ls -l "/{{ WORKSPACE_VAR }}" |
| 83 | + register: fetch_list |
| 84 | + delegate_to: localhost |
| 85 | + |
| 86 | + - name: Debug the list of files in /{{ WORKSPACE_VAR }} on localhost |
| 87 | + debug: |
| 88 | + msg: "Files in /{{ WORKSPACE_VAR }}: {{ fetch_list.stdout_lines }}" |
| 89 | + delegate_to: localhost |
| 90 | + |
| 91 | + - name: remove Tarball directories |
| 92 | + file: |
| 93 | + path: "{{ paths }}" |
| 94 | + state: absent |
| 95 | + vars: |
| 96 | + paths: |
| 97 | + - /tmp/percona-server-{{ lookup('env', 'PS_VERSION') }}.tar.gz |
| 98 | + - /tmp/percona-server-{{ lookup('env', 'PS_VERSION') }}-minimal.tar.gz |
| 99 | + - /tmp/percona-server-{{ lookup('env', 'PS_VERSION') }}-debug.tar.gz |
| 100 | + - /usr/percona-server |
| 101 | + - /tmp/percona-server-minimal |
| 102 | + - /tmp/percona-server-debug |
0 commit comments