Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Story #14016: Add troubleshoot playbook for VitamUI #2375

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions deployment/ansible-vitamui-exploitation/troubleshoot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
---
# Example: ansible-vitamui-exploitation/troubleshoot.yml -e 'confirmation=YES log_files_age=2'
# Optional parameters: -e 'sync_type=rsync excludes=gc*,access*'

# Confirm launching this playbook
- hosts: localhost
any_errors_fatal: yes
gather_facts: no
vars_prompt:
name: "confirmation"
prompt: "This playbook will collect logs and other useful information to help debugging your VitamUI instance.\n\nAre you sure you want to run this playbook ?\nAnswer with 'YES'"
default: "NO"
private: no
tasks:
- name: Check Confirmation
fail: msg="Playbook run confirmation failed"
when: confirmation | default(false) | bool == false
tags: always
run_once: true

- hosts: all
any_errors_fatal: yes
gather_facts: no
vars_prompt:
name: log_files_age
prompt: "Type the maximum age of the files you want to retrieve (in days)"
default: 2
private: no
tasks:
- name: Age check
fail:
msg: "log_files_age is not valid: {{ log_files_age }} <= 0"
when: log_files_age | int <= 0
- name: Register var
set_fact:
log_files_age: "{{ log_files_age }}"
run_once: true

GiooDev marked this conversation as resolved.
Show resolved Hide resolved
# Init troubleshoot
GiooDev marked this conversation as resolved.
Show resolved Hide resolved

- hosts: vitam
gather_facts: no
roles:
- init_troubleshoot
- resolvconf
GiooDev marked this conversation as resolved.
Show resolved Hide resolved
- check_parent_structure
- tree_deployment

# fetch logs
# application log

- hosts: hosts_cas_server
gather_facts: no
ignore_errors: true
roles:
- vitamui_log_files
vars:
component_name: "{{ vitamui.cas_server.vitamui_component }}"
age: "{{ log_files_age }}"

- hosts: hosts_vitamui_api_gateway
gather_facts: no
ignore_errors: true
roles:
- vitamui_log_files
vars:
component_name: "{{ vitamui.api_gateway.vitamui_component }}"
age: "{{ log_files_age }}"

- hosts: hosts_vitamui_referential_external
gather_facts: no
ignore_errors: true
roles:
- vitamui_log_files
vars:
component_name: "{{ vitamui.referential_external.vitamui_component }}"
age: "{{ log_files_age }}"

- hosts: hosts_vitamui_iam_external
gather_facts: no
ignore_errors: true
roles:
- vitamui_log_files
vars:
component_name: "{{ vitamui.iam_external.vitamui_component }}"
age: "{{ log_files_age }}"

- hosts: hosts_vitamui_iam_internal
gather_facts: no
ignore_errors: true
roles:
- vitamui_log_files
vars:
component_name: "{{ vitamui.iam_internal.vitamui_component }}"
age: "{{ log_files_age }}"

- hosts: hosts_vitamui_security_internal
gather_facts: no
ignore_errors: true
roles:
- vitamui_log_files
vars:
component_name: "{{ vitamui.security_internal.vitamui_component }}"
age: "{{ log_files_age }}"

- hosts: hosts_vitamui_ingest_external
gather_facts: no
ignore_errors: true
roles:
- vitamui_log_files
vars:
component_name: "{{ vitamui.ingest_external.vitamui_component }}"
age: "{{ log_files_age }}"

- hosts: hosts_vitamui_ingest_internal
gather_facts: no
ignore_errors: true
roles:
- vitamui_log_files
vars:
component_name: "{{ vitamui.ingest_internal.vitamui_component }}"
age: "{{ log_files_age }}"

- hosts: hosts_vitamui_archive_search_external
gather_facts: no
ignore_errors: true
roles:
- vitamui_log_files
vars:
component_name: "{{ vitamui.archive_search_external.vitamui_component }}"
age: "{{ log_files_age }}"

- hosts: hosts_vitamui_archive_search_internal
gather_facts: no
ignore_errors: true
roles:
- vitamui_log_files
vars:
component_name: "{{ vitamui.archive_search_internal.vitamui_component }}"
age: "{{ log_files_age }}"

- hosts: hosts_vitamui_collect_external
gather_facts: no
ignore_errors: true
roles:
- vitamui_log_files
vars:
component_name: "{{ vitamui.collect_external.vitamui_component }}"
age: "{{ log_files_age }}"

- hosts: hosts_vitamui_collect_internal
gather_facts: no
ignore_errors: true
roles:
- vitamui_log_files
vars:
component_name: "{{ vitamui.collect_internal.vitamui_component }}"
age: "{{ log_files_age }}"

- hosts: hosts_vitamui_pastis_external
gather_facts: no
ignore_errors: true
roles:
- vitamui_log_files
vars:
component_name: "{{ vitamui.pastis_external.vitamui_component }}"
age: "{{ log_files_age }}"

# End troubleshoot

- hosts: hosts_vitamui
gather_facts: no
roles:
- end_troubleshoot
14 changes: 14 additions & 0 deletions deployment/roles/check_parent_structure/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---

- name: check whether VITAMUI parent dir already exists
stat:
path: "{{ vitamui_defaults.folder.root_path }}"
register: root_dir

- name: fail if this VITAMUI parent dir is a symlink
#shell: echo "root vitam dir is symlink" > {{ inventory_dir }}/troubleshoot/{{ inventory_hostname }}/vitam_root_dir_symlink.txt
copy:
content: "root vitam dir is symlink"
dest: "{{ inventory_dir }}/troubleshoot/{{ inventory_hostname }}/vitam_root_dir_symlink.txt"
delegate_to: localhost
when: root_dir.stat.islnk is defined and root_dir.stat.islnk == "true"
22 changes: 22 additions & 0 deletions deployment/roles/end_troubleshoot/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: archive troubleshoot
archive:
path: "{{ inventory_dir }}/troubleshoot/"
dest: "{{ inventory_dir }}/troubleshoot_{{ ansible_date_time.date }}T{{ ansible_date_time.time }}-{{ log_files_age }}d_{{ vitamui_site_name }}.zip"
remove: yes
format: zip
delegate_to: localhost
run_once: true

- name: remove troubleshoot directory
file:
path: "{{ inventory_dir }}/troubleshoot/"
state: absent
delegate_to: localhost
run_once: true

- name: display post install message
debug:
msg: "Please send generated {{ inventory_dir }}/troubleshoot_{{ ansible_date_time.date }}T{{ ansible_date_time.time }}-{{ log_files_age }}d_{{ vitamui_site_name }}.zip file by mail to Vitam support"
delegate_to: localhost
run_once: true
16 changes: 16 additions & 0 deletions deployment/roles/gather_host/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---

- name: gather facts
setup:
register: faits

# - name: test
# debug:
# msg: "{{ faits }}"

- name: get back facts
copy:
content: "{{ faits }}"
dest: "{{ inventory_dir }}/troubleshoot/{{ inventory_hostname }}/facts.json"
mode: 0775
delegate_to: localhost
33 changes: 33 additions & 0 deletions deployment/roles/init_troubleshoot/tasks/mail.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---

- name: init troubleshoot directories
file:
path: "{{ inventory_dir }}/troubleshoot/{{ inventory_hostname }}/"
state: directory
mode: 0777
delegate_to: localhost

# If sync_type == 'rsync'
- block:

- name: ensure rsync package is installed for synchronize module
package:
name: rsync
state: present
register: result
retries: "{{ packages_install_retries_number }}"
until: result is succeeded
delay: "{{ packages_install_retries_delay }}"

- name: ensure rsync is installed locally for synchronize module
package:
name: rsync
state: present
register: result
retries: "{{ packages_install_retries_number }}"
until: result is succeeded
delay: "{{ packages_install_retries_delay }}"
run_once: true
delegate_to: localhost

when: sync_type | default('fetch') | lower == 'rsync'
7 changes: 7 additions & 0 deletions deployment/roles/resolvconf/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

- name: get back /etc/resolv.conf
fetch:
src: "/etc/resolv.conf"
dest: "{{ inventory_dir }}/troubleshoot/{{ inventory_hostname }}/resolv.conf"
flat: yes
16 changes: 16 additions & 0 deletions deployment/roles/tree_deployment/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---

- name: Install tree package
ignore_errors: true
become: true
package:
name: tree
state: present
delegate_to: localhost
run_once: true

- name: list all files
ignore_errors: true
shell: tree -a ../../ > {{ inventory_dir }}/troubleshoot/listing_ansible.txt
delegate_to: localhost
run_once: true
45 changes: 45 additions & 0 deletions deployment/roles/vitamui_log_files/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---

- name: list files from {{ vitamui_defaults.folder.root_path | default('/vitamui') }}/log/{{ component_name }}
find:
paths: "{{ vitamui_defaults.folder.root_path | default('/vitamui') }}/log/{{ component_name }}"
age: "-{{ age }}d"
recurse: no # no subdir
file_type: file
excludes: "java_pid*,{{ excludes | default('') }}"
register: path_files

# Run the rest only if there is files to get
- block:

- name: create list of files
set_fact: fichier="{{ item.path }}"
with_items: "{{ path_files.files }}"
register: filespath

- name: Create a temp zip archive from {{ component_name }}
archive:
path: "{{ filespath.results| map(attribute='ansible_facts.fichier') | list }}"
dest: "{{ vitamui_defaults.folder.root_path | default('/vitamui') }}/tmp/{{ component_name }}/{{ component_name }}.zip"
format: zip

- name: fetch zip file from {{ component_name }} with rsync method
synchronize:
mode: pull
src: "{{ vitamui_defaults.folder.root_path | default('/vitamui') }}/tmp/{{ component_name }}/{{ component_name }}.zip"
dest: "{{ inventory_dir }}/troubleshoot/{{ inventory_hostname }}/{{ component_name }}/"
when: sync_type | default('fetch') | lower == 'rsync'

- name: fetch zip file from {{ component_name }} with fetch method
fetch:
src: "{{ vitamui_defaults.folder.root_path | default('/vitamui') }}/tmp/{{ component_name }}/{{ component_name }}.zip"
dest: "{{ inventory_dir }}/troubleshoot/{{ inventory_hostname }}/{{ component_name }}/{{ component_name }}.zip"
flat: yes
when: sync_type | default('fetch') | lower == 'fetch'

- name: remove temp zip file on host
file:
path: "{{ vitamui_defaults.folder.root_path | default('/vitamui') }}/tmp/{{ component_name }}/{{ component_name }}.zip"
state: absent

when: path_files is defined and path_files.matched > 0
Loading