---

# TODO: voir comment faire des backups initiaux des fichiers

- name: Copy rsyslog.conf
  copy:
    src: logs/rsyslog.conf
    dest: /etc/rsyslog.conf
    mode: "0644"
  notify: restart rsyslog
  when: evolinux_logs_rsyslog_conf | bool

- name: Disable logrotate default conf
  command: mv /etc/logrotate.d/rsyslog /etc/logrotate.d/rsyslog.disabled
  args:
    removes: /etc/logrotate.d/rsyslog
    creates: /etc/logrotate.d/rsyslog.disabled
  notify: restart rsyslog
  when: evolinux_logs_disable_logrotate_rsyslog | bool

- name: Copy many logrotate files
  copy:
    src: logs/logrotate.d/
    dest: /etc/logrotate.d/
  when: evolinux_logs_logrotate_confs | bool

- name: Copy rsyslog logrotate file
  template:
    src: logs/zsyslog.j2
    dest: /etc/logrotate.d/zsyslog
  when: evolinux_logs_logrotate_confs | bool

- name: Configure logrotate.conf default rotate value
  replace:
    dest: /etc/logrotate.conf
    regexp: "rotate [0-9]+"
    replace: "rotate 12"
  when: evolinux_logs_default_rotate | bool

- name: Enable logrotate.conf dateext option
  lineinfile:
    dest: /etc/logrotate.conf
    line: "dateext"
    regexp: "^#?\\s*dateext"
  when: evolinux_logs_default_dateext | bool

- name: Enable logrotate.conf dateformat option
  lineinfile:
    dest: /etc/logrotate.conf
    line: "dateformat {{ evolinux_logrotate_dateformat | mandatory }}"
    regexp: "^#?\\s*dateformat.*"
    insertafter: 'dateext'
  when: evolinux_logs_default_dateext | bool

- name: Disable logrotate.conf dateyesterday option
  lineinfile:
    dest: /etc/logrotate.conf
    line: "# dateyesterday"
    regexp: "^\\s*dateyesterday"
    insertafter: 'dateext'
  when: evolinux_logs_default_dateext | bool

- meta: flush_handlers
