diff --git a/README.md b/README.md index 1186fca..54580e1 100644 --- a/README.md +++ b/README.md @@ -99,3 +99,20 @@ Checks the health of the Appliances. #### Required groups * cfme-appliancees + +### gather-logs.yml +Gathers relevant logs from all of the appliances and puts them in an archive on the first DB host. Optionally emails the archive. + +#### Required groups +* cfme-databases + +#### Options +| parameter | required | default | comments +|-------------------------------------------|----------|------------------------------------------------------------------- +| cfme\_gather\_logs\_smtp\_host | No | | SMTP host to send log archive email through. If not specified no email will be sent. +| cfme\_gather\_logs\_smtp\_port | No | | SMTP port to send log archive email through. If not specified no em + ail will be sent. +| cfme\_gather\_logs\_email\_from | No | | Email addresses to send the log archive email from. If not specified no em + ail will be sent. +| cfme\_gather\_logs\_email\_to | No | | Email addresses to send the log archive email to. If not specified no em + ail will be sent. diff --git a/playbooks/gather-logs.yml b/playbooks/gather-logs.yml new file mode 100644 index 0000000..2a722c0 --- /dev/null +++ b/playbooks/gather-logs.yml @@ -0,0 +1,84 @@ +- name: CFME | Gather Logs + hosts: all + gather_facts: True + tasks: + - name: CFME | Gather Logs | Set destination host + set_fact: + cfme_gather_logs_destination_host: "{{ groups['cfme-databases'][0] }}" + + - name: CFME | Gather Logs | Get destionation public key + slurp: + src: '~/.ssh/id_rsa.pub' + delegate_to: "{{ cfme_gather_logs_destination_host }}" + register: cfme_destination_pub_key + + - name: CFME | Gather Logs | Add destination public key as authorized key + authorized_key: + user: "{{ ansible_user }}" + state: present + validate_certs: False + key: "{{ cfme_destination_pub_key['content'] | b64decode }}" + + - name: CFME | Gather Logs | Determine destination dir + set_fact: + cfme_gather_logs_destination_dir: "/tmp/ansible-cfme-gather-logs_{{ ansible_date_time.date }}_{{ ansible_date_time.hour }}{{ ansible_date_time.minute }}{{ ansible_date_time.second }}" + delegate_to: "{{ cfme_gather_logs_destination_host }}" + run_once: True + + - name: CFME | Gather Logs | Set destination dir + set_fact: + cfme_gather_logs_destination_dir: "{{ hostvars[cfme_gather_logs_destination_host]['cfme_gather_logs_destination_dir'] }}" + + - name: CFME | Gather Logs | Create destination directory + file: + path: "{{ cfme_gather_logs_destination_dir }}" + state: directory + mode: 0777 + recurse: True + run_once: True + delegate_to: "{{ cfme_gather_logs_destination_host }}" + become: True + + - name: CFME | Gather Logs | Syncronize logs + synchronize: + mode: pull + archive: No + src: "/var/www/miq/vmdb/log/{{ item }}" + dest: "{{ cfme_gather_logs_destination_dir }}/{{ item }}-{{ inventory_hostname }}" + delegate_to: "{{ cfme_gather_logs_destination_host }}" + with_items: + - evm.log + - automation.log + + - name: CFME | Gather Logs | Create archive + archive: + path: "{{ cfme_gather_logs_destination_dir }}" + dest: "{{ cfme_gather_logs_destination_dir }}.tgz" + run_once: True + delegate_to: "{{ cfme_gather_logs_destination_host }}" + + - name: CFME | Gather Logs | Send email with logs attached + mail: + host: "{{ cfme_gather_logs_smtp_host }}" + port: "{{ cfme_gather_logs_smtp_port }}" + secure: never + from: "{{ cfme_gather_logs_email_from }}" + to: "{{ cfme_gather_logs_email_to }}" + subject: CFME Logs + body: "CFME logs gathered from cluster and sent from {{ inventory_hostname }}." + attach: "{{ cfme_gather_logs_destination_dir }}.tgz" + run_once: True + delegate_to: "{{ cfme_gather_logs_destination_host }}" + when: + - "cfme_gather_logs_smtp_host is defined" + - "cfme_gather_logs_smtp_port is defined" + - "cfme_gather_logs_email_from is defined" + - "cfme_gather_logs_email_to is defined" + + - name: CFME | Gather Logs | Delete destination directory + file: + path: "{{ cfme_gather_logs_destination_dir }}" + state: absent + run_once: True + delegate_to: "{{ cfme_gather_logs_destination_host }}" + become: True