From b5fb5046aed68612cb7816d97db4ae2ad3058f43 Mon Sep 17 00:00:00 2001 From: Abderrahman Bouayad Date: Thu, 9 Jan 2025 11:56:24 +0100 Subject: [PATCH] add playbook troubleshoot vitamui --- .../check_parent_structure/tasks/main.yml | 14 ++ .../roles/end_troubleshoot/tasks/main.yml | 22 +++ .../roles/gather_host/tasks/main.yml | 16 ++ .../roles/init_troubleshoot/tasks/mail.yml | 33 ++++ .../roles/resolvconf/tasks/main.yml | 7 + .../roles/tree_deployment/tasks/main.yml | 20 ++ .../roles/vitamui_log_files/tasks/main.yml | 45 +++++ .../troubleshoot.yml | 182 ++++++++++++++++++ .../group_vars/all/vitamui_vars.yml | 3 + 9 files changed, 342 insertions(+) create mode 100644 deployment/ansible-vitamui-exploitation/roles/check_parent_structure/tasks/main.yml create mode 100644 deployment/ansible-vitamui-exploitation/roles/end_troubleshoot/tasks/main.yml create mode 100644 deployment/ansible-vitamui-exploitation/roles/gather_host/tasks/main.yml create mode 100644 deployment/ansible-vitamui-exploitation/roles/init_troubleshoot/tasks/mail.yml create mode 100644 deployment/ansible-vitamui-exploitation/roles/resolvconf/tasks/main.yml create mode 100644 deployment/ansible-vitamui-exploitation/roles/tree_deployment/tasks/main.yml create mode 100644 deployment/ansible-vitamui-exploitation/roles/vitamui_log_files/tasks/main.yml create mode 100644 deployment/ansible-vitamui-exploitation/troubleshoot.yml diff --git a/deployment/ansible-vitamui-exploitation/roles/check_parent_structure/tasks/main.yml b/deployment/ansible-vitamui-exploitation/roles/check_parent_structure/tasks/main.yml new file mode 100644 index 00000000000..9387ca22231 --- /dev/null +++ b/deployment/ansible-vitamui-exploitation/roles/check_parent_structure/tasks/main.yml @@ -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" diff --git a/deployment/ansible-vitamui-exploitation/roles/end_troubleshoot/tasks/main.yml b/deployment/ansible-vitamui-exploitation/roles/end_troubleshoot/tasks/main.yml new file mode 100644 index 00000000000..bc4e4bae1e4 --- /dev/null +++ b/deployment/ansible-vitamui-exploitation/roles/end_troubleshoot/tasks/main.yml @@ -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_{{ vitam_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_{{ vitam_site_name }}.zip file by mail to Vitamui support" + delegate_to: localhost + run_once: true diff --git a/deployment/ansible-vitamui-exploitation/roles/gather_host/tasks/main.yml b/deployment/ansible-vitamui-exploitation/roles/gather_host/tasks/main.yml new file mode 100644 index 00000000000..7fcb52e3e63 --- /dev/null +++ b/deployment/ansible-vitamui-exploitation/roles/gather_host/tasks/main.yml @@ -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 diff --git a/deployment/ansible-vitamui-exploitation/roles/init_troubleshoot/tasks/mail.yml b/deployment/ansible-vitamui-exploitation/roles/init_troubleshoot/tasks/mail.yml new file mode 100644 index 00000000000..84f6888fb7f --- /dev/null +++ b/deployment/ansible-vitamui-exploitation/roles/init_troubleshoot/tasks/mail.yml @@ -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' diff --git a/deployment/ansible-vitamui-exploitation/roles/resolvconf/tasks/main.yml b/deployment/ansible-vitamui-exploitation/roles/resolvconf/tasks/main.yml new file mode 100644 index 00000000000..4d1a14c9dba --- /dev/null +++ b/deployment/ansible-vitamui-exploitation/roles/resolvconf/tasks/main.yml @@ -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 diff --git a/deployment/ansible-vitamui-exploitation/roles/tree_deployment/tasks/main.yml b/deployment/ansible-vitamui-exploitation/roles/tree_deployment/tasks/main.yml new file mode 100644 index 00000000000..6f0ab8aa5de --- /dev/null +++ b/deployment/ansible-vitamui-exploitation/roles/tree_deployment/tasks/main.yml @@ -0,0 +1,20 @@ +--- + +- name: Install tree package + ignore_errors: true + become: true + package: + name: tree + state: present + register: result + retries: "{{ packages_install_retries_number }}" + until: result is succeeded + delay: "{{ packages_install_retries_delay }}" + 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 diff --git a/deployment/ansible-vitamui-exploitation/roles/vitamui_log_files/tasks/main.yml b/deployment/ansible-vitamui-exploitation/roles/vitamui_log_files/tasks/main.yml new file mode 100644 index 00000000000..613133b4aa1 --- /dev/null +++ b/deployment/ansible-vitamui-exploitation/roles/vitamui_log_files/tasks/main.yml @@ -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 diff --git a/deployment/ansible-vitamui-exploitation/troubleshoot.yml b/deployment/ansible-vitamui-exploitation/troubleshoot.yml new file mode 100644 index 00000000000..9f0c54a3ce5 --- /dev/null +++ b/deployment/ansible-vitamui-exploitation/troubleshoot.yml @@ -0,0 +1,182 @@ +--- +# Example: ansible-vitamui-exploitation/troubleshoot.yml -e 'confirmation=YES log_files_age=2' +# Optional parameters: -e 'sync_type=rsync get_crt=yes 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 + + +# Init troubleshoot +- hosts: vitam + gather_facts: no + roles: + - init_troubleshoot + - resolvconf +# - tree_deployment + - check_parent_structure + + +# 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 +# ignore_errors: true +# roles: +# - { role: get_crt_files, when: get_crt | default(false) | bool == true } + +- hosts: hosts_vitamui + gather_facts: no + roles: + - end_troubleshoot diff --git a/deployment/environments/group_vars/all/vitamui_vars.yml b/deployment/environments/group_vars/all/vitamui_vars.yml index 97c6652ca54..44c24e495ae 100755 --- a/deployment/environments/group_vars/all/vitamui_vars.yml +++ b/deployment/environments/group_vars/all/vitamui_vars.yml @@ -300,3 +300,6 @@ opentracing: syslog: name: filebeat # or rsyslog + +packages_install_retries_number: 1 +packages_install_retries_delay: 10