diff --git a/ansible/logs/get-overcloud-logs.yml b/ansible/logs/get-overcloud-logs.yml new file mode 100644 index 000000000..d50db28cf --- /dev/null +++ b/ansible/logs/get-overcloud-logs.yml @@ -0,0 +1,56 @@ +--- +- hosts: controller + remote_user: "{{host_remote_user}}" + vars_files: + - ../install/group_vars/all.yml + vars: + services: + - nova + - neutron + - ceilometer + - cinder + - gnocchi + - keystone + - heat + become: true + tags: + - controller + pre_tasks: + - name: Create logs directory + file: + path: /home/{{host_remote_user}}/{{ansible_hostname}} + state: directory + roles: + - osp_version + - common + - glance + - mysql + - rabbitmq + - httpd + - openvswitch + - common + - fetch-logs + +- hosts: compute + remote_user: "{{host_remote_user}}" + vars_files: + - ../install/group_vars/all.yml + vars: + services: + - nova + - neutron + - ceilometer + - libvirt + become: true + tags: + - compute + pre_tasks: + - name: Create logs directory + file: + path: /home/{{host_remote_user}}/{{ansible_hostname}} + state: directory + roles: + - common + - openvswitch + - fetch-logs + diff --git a/ansible/logs/roles/common/tasks/main.yml b/ansible/logs/roles/common/tasks/main.yml new file mode 100644 index 000000000..9bb3273bd --- /dev/null +++ b/ansible/logs/roles/common/tasks/main.yml @@ -0,0 +1,88 @@ +- name: Check that service is installed + stat: + path: /etc/{{item}}/{{item}}.conf + register: config + with_items: "{{services}}" + +- name: Check if service is containerized + shell: + cmd: docker ps | grep {{item.item}} + register: container + when: item.stat.exists + with_items: + - "{{config.results}}" + ignore_errors: true + +- name: Set log location (containerized) + set_fact: + log_dir_containerized: /var/log/containers/{{item.0.item}} + register: log_result_containerized + when: item.1.rc == 0 and item.0.stat.exists + with_together: + - "{{config.results}}" + - "{{container.results}}" + +- name: Set log location (non-containerized) + set_fact: + log_dir_noncontainerized: /var/log/{{item.0.item}} + register: log_result_noncontainerized + when: item.1.rc != 0 and item.0.stat.exists + with_together: + - "{{config.results}}" + - "{{container.results}}" + +- name: make list of log directories (containerized) + set_fact: + log_dir_containerized: "{{ log_result_containerized.results | selectattr('ansible_facts','defined') | map(attribute='ansible_facts.log_dir_containerized') | list }}" + when: item.1.rc == 0 and item.0.stat.exists + with_together: + - "{{config.results}}" + - "{{container.results}}" + + +- name: make list of log directories (non-containerized) + set_fact: + log_dir_noncontainerized: "{{ log_result_noncontainerized.results | selectattr('ansible_facts','defined') | map(attribute='ansible_facts.log_dir_noncontainerized') | list }}" + when: item.1.rc != 0 and item.0.stat.exists + with_together: + - "{{config.results}}" + - "{{container.results}}" + + +- name: Check if log folder exists (container) + stat: + path: "{{item}}" + register: logs_path_containerized + with_items: + - "{{log_dir_containerized}}" + when: log_dir_containerized is defined + +- name: Check if log folder exists (non-container) + stat: + path: "{{item}}" + register: logs_path_noncontainerized + with_items: + - "{{log_dir_noncontainerized}}" + when: log_dir_noncontainerized is defined + +- name: Copy container logs to directory on host + synchronize: + src: "{{item.1.item}}" + dest: /home/{{host_remote_user}}/{{ansible_hostname}} + delegate_to: "{{ inventory_hostname }}" + when: log_dir_containerized is defined and item.0.stat.exists and item.1.stat is defined and item.1.stat.isdir is defined and item.1.stat.isdir + with_together: + - "{{config.results}}" + - "{{logs_path_containerized.results}}" + +- name: Copy non-container logs to directory on host + synchronize: + src: "{{item.1.item}}" + dest: /home/{{host_remote_user}}/{{ansible_hostname}} + delegate_to: "{{ inventory_hostname }}" + when: log_dir_noncontainerized is defined and item.0.stat.exists and item.1.stat is defined and item.1.stat.isdir is defined and item.1.stat.isdir + with_together: + - "{{config.results}}" + - "{{logs_path_noncontainerized.results}}" + + diff --git a/ansible/logs/roles/fetch-logs/tasks/main.yml b/ansible/logs/roles/fetch-logs/tasks/main.yml new file mode 100644 index 000000000..92d57e173 --- /dev/null +++ b/ansible/logs/roles/fetch-logs/tasks/main.yml @@ -0,0 +1,18 @@ +--- +- name: Tar the logs directory + archive: + path: /home/{{host_remote_user}}/{{ansible_hostname}} + dest: /home/{{host_remote_user}}/{{ansible_hostname}}.gz + +- name: Remove logs directory + file: + path: /home/{{host_remote_user}}/{{ansible_hostname}} + state: absent + +- name: Fetch logs + fetch: + src: /home/{{host_remote_user}}/{{ansible_hostname}}.gz + dest: + /home/{{browbeat_user}}/logs/{{inventory_hostname}}-{{ansible_date_time.epoch}} + flat: yes + diff --git a/ansible/logs/roles/glance/tasks/main.yml b/ansible/logs/roles/glance/tasks/main.yml new file mode 100644 index 000000000..8b538514a --- /dev/null +++ b/ansible/logs/roles/glance/tasks/main.yml @@ -0,0 +1,35 @@ +--- +- name: Check that glance is installed + stat: + path: /etc/glance/glance-api.conf + register: glance_config + +- name: Check if glance is containerized + shell: + cmd: docker ps | grep glance + register: glance_container + when: glance_config.stat.exists + ignore_errors: true + +- name: Set glance log location (containerized) + set_fact: + glance_logs: /var/log/containers/glance + when: glance_container.rc == 0 and glance_config.stat.exists + +- name: Set glance log location (non-containerized) + set_fact: + glance_logs: /var/log/glance + when: glance_container.rc != 0 and glance_config.stat.exists + +- name: Check if log folder exists + stat: + path: "{{glance_logs}}" + register: logs_path + +- name: Copy logs to directory on host + synchronize: + src: "{{glance_logs}}" + dest: /home/{{host_remote_user}}/{{ansible_hostname}} + delegate_to: "{{ inventory_hostname }}" + when: glance_config.stat.exists and logs_path.stat.isdir is defined and logs_path.stat.isdir + diff --git a/ansible/logs/roles/httpd/tasks/main.yml b/ansible/logs/roles/httpd/tasks/main.yml new file mode 100644 index 000000000..70b41fdc3 --- /dev/null +++ b/ansible/logs/roles/httpd/tasks/main.yml @@ -0,0 +1,28 @@ +--- +- name: Check that httpd is installed + stat: + path: /etc/httpd/conf/httpd.conf + register: httpd_config + +- name: Set httpd log location (containerized) + set_fact: + httpd_logs: /var/log/containers/httpd + when: osp_version >= 12 and httpd_config.stat.exists + +- name: Set httpd log location (non-containerized) + set_fact: + httpd_logs: /var/log/httpd + when: osp_version < 12 and httpd_config.stat.exists + +- name: Check if log folder exists + stat: + path: "{{httpd_logs}}" + register: logs_path + +- name: Copy logs to directory on host + synchronize: + src: "{{httpd_logs}}" + dest: /home/{{host_remote_user}}/{{ansible_hostname}} + delegate_to: "{{ inventory_hostname }}" + when: httpd_config.stat.exists and logs_path.stat.isdir is defined and logs_path.stat.isdir + diff --git a/ansible/logs/roles/mysql/tasks/main.yml b/ansible/logs/roles/mysql/tasks/main.yml new file mode 100644 index 000000000..aead213a9 --- /dev/null +++ b/ansible/logs/roles/mysql/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- name: Check that mysql is installed + stat: + path: /etc/my.cnf.d/galera.cnf + register: mysql_config + +- name: Check if mysql is containerized + shell: + cmd: docker ps | grep mariadb + register: mysql_container + when: mysql_config.stat.exists + ignore_errors: true + +- name: Set mysql log location (containerized) + set_fact: + mysql_logs: /var/log/containers/mysql + when: mysql_container.rc == 0 and mysql_config.stat.exists + +- name: Check if log folder exists + stat: + path: "{{mysql_logs}}" + register: logs_path + +- name: Copy logs to directory on host + synchronize: + src: "{{mysql_logs}}" + dest: /home/{{host_remote_user}}/{{ansible_hostname}} + delegate_to: "{{ inventory_hostname }}" + when: mysql_config.stat.exists and logs_path.stat.isdir is defined and logs_path.stat.isdir + diff --git a/ansible/logs/roles/openvswitch/tasks/main.yml b/ansible/logs/roles/openvswitch/tasks/main.yml new file mode 100644 index 000000000..7c09d1ff5 --- /dev/null +++ b/ansible/logs/roles/openvswitch/tasks/main.yml @@ -0,0 +1,23 @@ +--- +- name: Check that openvswitch is installed + stat: + path: /etc/openvswitch/default.conf + register: openvswitch_config + +- name: Set openvswitch log location (non-containerized) + set_fact: + openvswitch_logs: /var/log/openvswitch + when: openvswitch_config.stat.exists + +- name: Check if log folder exists + stat: + path: "{{openvswitch_logs}}" + register: logs_path + +- name: Copy logs to directory on host + synchronize: + src: "{{openvswitch_logs}}" + dest: /home/{{host_remote_user}}/{{ansible_hostname}} + delegate_to: "{{ inventory_hostname }}" + when: openvswitch_config.stat.exists and logs_path.stat.isdir is defined and logs_path.stat.isdir + diff --git a/ansible/logs/roles/rabbitmq/tasks/main.yml b/ansible/logs/roles/rabbitmq/tasks/main.yml new file mode 100644 index 000000000..774747232 --- /dev/null +++ b/ansible/logs/roles/rabbitmq/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- name: Check that rabbitmq is installed + stat: + path: /etc/rabbitmq/rabbitmq.config + register: rabbitmq_config + +- name: Check if rabbitmq is containerized + shell: + cmd: docker ps | grep rabbitmq + register: rabbitmq_container + when: rabbitmq_config.stat.exists + ignore_errors: true + +- name: Set rabbitmq log location (containerized) + set_fact: + rabbitmq_logs: /var/log/containers/rabbitmq + when: rabbitmq_container.rc == 0 and rabbitmq_config.stat.exists + +- name: Check if log folder exists + stat: + path: "{{rabbitmq_logs}}" + register: logs_path + +- name: Copy logs to directory on host + synchronize: + src: "{{rabbitmq_logs}}" + dest: /home/{{host_remote_user}}/{{ansible_hostname}} + delegate_to: "{{ inventory_hostname }}" + when: rabbitmq_config.stat.exists and logs_path.stat.isdir is defined and logs_path.stat.isdir +