---

- name: Install packages
  apt:
    name:
      - mongodb
      - mongo-tools
    state: present

- name: install dependency for monitoring
  apt:
    name: python-pymongo
    state: present

- name: Custom configuration
  template:
    src: mongodb_stretch.conf.j2
    dest: "/etc/mongodb.conf"
    force: "{{ mongodb_force_config | bool | ternary('yes', 'no') }}"
  notify: restart mongodb

- name: enable service
  service:
    name: mongodb
    enabled: yes

- name: Configure logrotate
  template:
    src: logrotate_stretch.j2
    dest: /etc/logrotate.d/mongodb-server
    force: yes
    backup: no

- name: disable previous logrotate
  command: mv /etc/logrotate.d/mongodb /etc/logrotate.d/mongodb.disabled
  args:
    removes: /etc/logrotate.d/mongodb
    creates: /etc/logrotate.d/mongodb.disabled
