---
# tasks file for mongodb_install
- name: Install MongoDB Packages
  package:
    name: mongodb-org
    state: present
  when: specific_mongodb_version is not defined
  register: _pkg
  until: _pkg is succeeded
  retries: 5

- name: Install MongoDB Packages (Specific version)
  package:
    name: "mongodb-org-{{ specific_mongodb_version }}"
    state: present
  when:
    - specific_mongodb_version is defined
    - ansible_facts.os_family == "RedHat"
  register: _pkg
  until: _pkg is succeeded
  retries: 5

# apt silliness:
# In order to upgrade/downgrade to a specific version of mongodb-org,
# we must also specifiy version of mongodb-org deps.
# https://dba.stackexchange.com/questions/197336/how-to-install-specific-mongo-version-from-the-ppa
- name: Install MongoDB Packages (Specific version)
  package:
    name:
      - "mongodb-org={{ specific_mongodb_version }}"
      - "mongodb-org-server={{ specific_mongodb_version }}"
      - "mongodb-org-shell={{ specific_mongodb_version }}"
      - "mongodb-org-mongos={{ specific_mongodb_version }}"
      - "mongodb-org-tools={{ specific_mongodb_version }}"
    state: present
  when:
    - specific_mongodb_version is defined
    - ansible_facts.os_family == "Debian"
  register: _pkg
  until: _pkg is succeeded
  retries: 5
