Ansible role that installs and configures mongodb https://www.mongodb.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
4.7 KiB

---
- block:
- name: Check if Service mongod Exists
stat: path=/etc/init/mongod
register: service_mongod_status
tags: mongodb
- name: Ensure mongod is stopped and disabled
service: name=mongod state=stopped enabled=no
when:
- service_mongod_status.stat.exists
- mongodb_start_server is defined
- mongodb_start_server == 'no'
- mongodb_install_conf
when:
- mongodb_install_server
- mongodb_install_from_external_repo
tags: mongodb
- block:
- name: Install the mongodb-org apt keys
apt_key: keyserver='hkp://keyserver.ubuntu.com:80' id={{ item }} state=present
with_items: '{{ mongodb_repo_keys }}'
when: mongodb_install_from_external_repo
register: apt_key_update_cache
- name: Remove the old mongodb-org apt repositories
apt_repository: repo='{{ item }}' state=absent update_cache=yes
with_items: '{{ mongodb_old_repositories }}'
when: mongodb_upgrade_from_older_version
- name: Install the mongodb-org repository
apt_repository: repo="{{ mongodb_apt_repository }}" update_cache=yes state=present
- name: Install/Update the mongodb-org configuration
template: src=mongod-{{ mongodb_version }}.conf.j2 dest=/etc/mongod.conf owner=root group=root mode=0444 backup=yes
when: mongodb_install_conf
notify: Restart mongod
tags: [ 'mongodb', 'mongodb_update_conf', 'mongodb_keyfile' ]
when:
- mongodb_install_server
- mongodb_install_from_external_repo
tags: [ 'mongodb' ]
- block:
- name: We are upgrading, install the latest version of the mongodb-org packages, external repository
apt: pkg={{ mongodb_server_pkgs_external_repo }} state=latest update_cache=yes cache_valid_time=1800
when: mongodb_upgrade_from_older_version
- name: Install the mongodb-org packages, external repository
apt: pkg={{ mongodb_server_pkgs_external_repo }} state={{ mongodb_pkg_state }} update_cache=yes cache_valid_time=1800
- name: Install the mongodb-org defaults file
template: src=mongod-default.j2 dest=/etc/default/mongod owner=root group=root mode=0444
when: mongodb_install_conf
notify: Restart mongod
tags: [ 'mongodb', 'mongodb_update_conf' ]
when:
- mongodb_install_server
- mongodb_install_packages
- mongodb_install_from_external_repo
tags: mongodb
- block:
- name: We are upgrading, install the latest version of the mongodb packages
apt: pkg={{ mongodb_server_pkgs }} state=latest update_cache=yes cache_valid_time=1800
when: mongodb_upgrade_from_older_version
- name: Install the mongodb packages
apt: pkg={{ mongodb_server_pkgs }} state={{ mongodb_pkg_state }} update_cache=yes cache_valid_time=1800
- name: Install/Update the mongodb configuration
template: src=mongod-{{ mongodb_version }}.conf.j2 dest=/etc/mongodb.conf owner=root group=root mode=0444 backup=yes
when: mongodb_install_conf
notify: Restart mongodb
tags: [ 'mongodb', 'mongodb_update_conf' ]
when:
- mongodb_install_server
- mongodb_install_packages
- not mongodb_install_from_external_repo
tags: mongodb
- block:
- name: Create the mongodb log directory
file: dest={{ mongodb_logdir }} state=directory owner={{ mongodb_user }} group={{ mongodb_group }} mode=0755
when: mongodb_install_conf
- name: Create the mongodb db directory
file: dest={{ mongodb_dbpath }} state=directory owner={{ mongodb_user }} group={{ mongodb_group }} mode=0755
when: mongodb_install_conf
- name: Install the cron job that manages log files rotation
template: src=mongo_log_rotate.sh.j2 dest=/etc/cron.daily/mongo_log_rotate owner=root group=root mode=0555
when: not mongodb_systemlog_external_logrotate
when: mongodb_install_server
tags: mongodb
- block:
- name: Ensure mongodb is started and enabled
service: name=mongodb state=started enabled=yes
when:
- mongodb_install_server
- mongodb_start_server == 'yes'
- not mongodb_install_from_external_repo
tags: mongodb
- block:
- name: Ensure mongodb-org is started and enabled
service: name=mongod state=started enabled=yes
when:
- mongodb_install_server
- mongodb_start_server == 'yes'
- mongodb_install_from_external_repo
tags: mongodb
- block:
- name: Install the mongodb client packages
apt: pkg={{ mongodb_client_pkgs }} state={{ mongodb_pkg_state }} cache_valid_time=1800
- name: Install the mongodb client packages, external repository
apt: pkg={{ mongodb_client_pkgs_external_repo }} state={{ mongodb_pkg_state }} cache_valid_time=1800
when: not mongodb_install_server
tags: [ 'mongodb', 'mongodb_client' ]