|
| 1 | +--- |
| 2 | +- name: Fetch logs |
| 3 | + hosts: ansible_control |
| 4 | + vars: |
| 5 | + fetch_logs_dest: "{{ lookup('env', 'PWD') }}/logs" |
| 6 | + diagnostics_path_control_host: "{{ ansible_facts.env.HOME }}/diagnostics" |
| 7 | + tasks: |
| 8 | + - name: Install rsync |
| 9 | + ansible.builtin.package: |
| 10 | + name: rsync |
| 11 | + become: true |
| 12 | + |
| 13 | + - name: Fetch Kayobe deployment logs |
| 14 | + ansible.builtin.fetch: |
| 15 | + src: "/home/{{ ansible_user }}/tmux.kayobe:0.log" |
| 16 | + dest: "{{ fetch_logs_dest }}/" |
| 17 | + fail_on_missing: false |
| 18 | + flat: true |
| 19 | + |
| 20 | + - name: Create diagnostics directory |
| 21 | + ansible.builtin.file: |
| 22 | + path: "{{ diagnostics_path_control_host }}" |
| 23 | + state: directory |
| 24 | + |
| 25 | + - name: Collect diagnostics |
| 26 | + ansible.builtin.shell: |
| 27 | + cmd: |- |
| 28 | + set -euo pipefail |
| 29 | + source ~/venvs/kayobe/bin/activate |
| 30 | + source ~/src/kayobe-config/kayobe-env --environment ci-multinode |
| 31 | + export KAYOBE_VAULT_PASSWORD=$(cat ~/vault.password) |
| 32 | + if [[ -f $KAYOBE_CONFIG_PATH/ansible/diagnostics.yml ]]; then |
| 33 | + kayobe playbook run $KAYOBE_CONFIG_PATH/ansible/diagnostics.yml -e diagnostics_path_local={{ diagnostics_path_control_host }} |
| 34 | + else |
| 35 | + echo "Missing diagnostics playbook - skipping" |
| 36 | + fi |
| 37 | + failed_when: false |
| 38 | + register: diagnostics_result |
| 39 | + |
| 40 | + # NOTE: In Ansible 2.10 and lower the synchronize module does not respect |
| 41 | + # SSH connection variables. This may result in Permission Denied issues if |
| 42 | + # using an SSH key that is not in ~/.ssh. |
| 43 | + - name: Fetch diagnostics |
| 44 | + ansible.posix.synchronize: |
| 45 | + src: "{{ diagnostics_path_control_host }}" |
| 46 | + dest: "{{ fetch_logs_dest }}/" |
| 47 | + mode: pull |
| 48 | + archive: no |
| 49 | + recursive: true |
| 50 | + copy_links: true |
| 51 | + verify_host: true |
| 52 | + # For jump host |
| 53 | + use_ssh_args: true |
| 54 | + when: diagnostics_result is success |
| 55 | + |
| 56 | + - name: Find Tempest results |
| 57 | + ansible.builtin.find: |
| 58 | + path: "/home/{{ ansible_user }}" |
| 59 | + # Also include old backed up results. |
| 60 | + patterns: "tempest-artifacts*" |
| 61 | + file_type: "directory" |
| 62 | + depth: 1 |
| 63 | + register: find_tempest_results |
| 64 | + |
| 65 | + # NOTE: In Ansible 2.10 and lower the synchronize module does not respect |
| 66 | + # SSH connection variables. This may result in Permission Denied issues if |
| 67 | + # using an SSH key that is not in ~/.ssh. |
| 68 | + - name: Fetch Tempest results |
| 69 | + ansible.posix.synchronize: |
| 70 | + src: "{{ item.path }}" |
| 71 | + dest: "{{ fetch_logs_dest }}/" |
| 72 | + mode: pull |
| 73 | + archive: no |
| 74 | + recursive: true |
| 75 | + copy_links: true |
| 76 | + verify_host: true |
| 77 | + # For jump host |
| 78 | + use_ssh_args: true |
| 79 | + loop: "{{ find_tempest_results.files }}" |
0 commit comments