diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..6b75479 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,9 @@ +--- +mongodb_version: 3.6 +mongodb_system_user: mongod +mongodb_system_group: mongod +mongodb_storage_dbpath: + + +# mongodb_system_gid: omit +# mongodb_system_uid: omit diff --git a/handlers/main.yml b/handlers/main.yml index 6b9ca07..d5760a6 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,9 +1,8 @@ --- -- name: Restart mongodb +- name: Restart mongod service systemd: name: mongod state: restarted enabled: yes daemon_reload: yes - listen: - - "mongod_restart" + listen: __mongod_restart diff --git a/tasks/install.yml b/tasks/install.yml index 6f860e7..981472e 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -1,28 +1,46 @@ --- - block: - - name: Add mongodb repo + - name: Add repository for major version '{{ mongodb_version }}' yum_repository: - name: mongodb-org-3.4 + name: mongodb description: MongoDB Repository - baseurl: https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/ + baseurl: "https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/{{ mongodb_version }}/x86_64/" gpgcheck: yes enabled: yes - gpgkey: https://www.mongodb.org/static/pgp/server-3.4.asc - notify: - - mongod_restart + gpgkey: "https://www.mongodb.org/static/pgp/server-{{ mongodb_version }}.asc" - - name: Install mongodb package + - name: Install package package: name: mongodb-org - state: latest - notify: - - mongod_restart + state: present - - name: Make sure mongodb is running - systemd: - name: mongod - state: started - enabled: yes - daemon_reload: yes + # - name: Create system group '{{ mongodb_system_group }}' + # group: + # name: "{{ mongodb_system_group }}" + # gid: "{{ mongodb_system_gid | default(omit) }}" + # state: present + # + # - name: Create system user '{{ mongodb_system_user }}' + # user: + # name: "{{ mongodb_system_user }}" + # uid: "{{ mongodb_system_uid | default(omit) }}" + # group: "{{ mongodb_system_group }}" + # notify: __mongod_restart + # + # - name: Create db storage dir at '{{ mongodb_storage_dbpath }}' + # file: + # path: "{{ mongodb_storage_dbpath }}" + # owner: "{{ mongodb_system_user }}" + # group: "{{ mongodb_system_group }}" + # follow: yes + # recurse: yes + # state: directory + # + # - name: Make sure mongodb is running + # systemd: + # name: mongod + # state: started + # enabled: yes + # daemon_reload: yes become: True become_user: root