diff --git a/.travis.yml b/.travis.yml index 2c7740d..e2e3d8b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -48,7 +48,6 @@ env: DISTRIBUTION=debian DIST_VERSION=9-builded MONGODB_VERSION=3.6 - MONGODB_PACKAGE=mongodb-org - > DISTRIBUTION=debian DIST_VERSION=8-builded diff --git a/defaults/main.yml b/defaults/main.yml index d6c15da..e5dd95c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -18,8 +18,8 @@ mongodb_manage_service: true mongodb_disable_transparent_hugepages: false mongodb_user: "{{ 'mongod' if ('RedHat' == ansible_os_family) else 'mongodb' }}" -mongodb_uid: "" -mongodb_gid: "" +mongodb_uid: +mongodb_gid: mongodb_daemon_name: "{{ 'mongod' if ('mongodb-org' in mongodb_package) else 'mongodb' }}" ## net Options diff --git a/tasks/configure.yml b/tasks/configure.yml index fff2a96..74a2d3b 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -1,7 +1,31 @@ --- +- name: create mongodb group + group: + name: "{{ mongodb_user }}" + state: present -- debug: - msg: "{{ mongodb_replication_replset }}" +- name: create mongodb user + user: + name: "{{ mongodb_user }}" + group: "{{ mongodb_user }}" + state: present + +# Workaround because default(omit) is not working. At least in Ansible 2.8. + +- name: set mongodb gid + group: + name: "{{ mongodb_user }}" + gid: "{{ mongodb_gid }}" + state: present + when: mongodb_gid is defined + +- name: set mongodb uid + user: + name: "{{ mongodb_user }}" + uid: "{{ mongodb_uid }}" + group: "{{ mongodb_user }}" + state: present + when: mongodb_uid is defined - name: Create keyFile copy: @@ -12,21 +36,6 @@ mode: 0600 when: mongodb_replication_replset | length > 0 -- name: set mongodb gid - group: - name: "{{ mongodb_user }}" - gid: "{{ mongodb_gid }}" - state: present - when: mongodb_gid | length > 0 - -- name: set mongodb uid - user: - name: "{{ mongodb_user }}" - uid: "{{ mongodb_uid }}" - group: "{{ mongodb_user }}" - state: present - when: mongodb_uid | length > 0 - - name: Create log dir if missing file: state: directory diff --git a/tasks/install.debian.yml b/tasks/install.debian.yml index 6921df9..6bd9c63 100644 --- a/tasks/install.debian.yml +++ b/tasks/install.debian.yml @@ -61,6 +61,8 @@ - name: Add systemd configuration if present copy: src=mongodb.service dest=/lib/systemd/system/mongodb.service owner=root group=root mode=0644 when: ansible_service_mgr == "systemd" + notify: + - reload systemd - name: Add symlink for systemd file: src=/lib/systemd/system/mongodb.service dest=/etc/systemd/system/multi-user.target.wants/mongodb.service state=link diff --git a/tasks/install.redhat.yml b/tasks/install.redhat.yml index b94e68e..f2b060d 100644 --- a/tasks/install.redhat.yml +++ b/tasks/install.redhat.yml @@ -15,6 +15,8 @@ dest: /etc/yum.repos.d/mongodb.repo mode: 0644 with_items: "{{ mongodb_major_version }}" + loop_control: + loop_var: version_item when: mongodb_package == 'mongodb-org' - name: Install MongoDB package @@ -38,11 +40,11 @@ name: - python-devel - python-pip - when: mongodb_pymongo_from_pip + when: mongodb_pymongo_from_pip | bool - name: Install PyMongo from PIP pip: name: pymongo state: "{{ mongodb_pymongo_pip_version is defined | ternary('present', 'latest') }}" version: "{{ mongodb_pymongo_pip_version | default(omit) }}" - when: mongodb_pymongo_from_pip + when: mongodb_pymongo_from_pip | bool diff --git a/templates/mongodb.repo.j2 b/templates/mongodb.repo.j2 index 1c84214..727f2cb 100644 --- a/templates/mongodb.repo.j2 +++ b/templates/mongodb.repo.j2 @@ -1,9 +1,9 @@ [mongodb-org-{{ mongodb_major_version }}] name=MongoDB {{ mongodb_major_version }} Repository -baseurl={{ mongodb_repository[item] }} -{% if mongodb_repository_gpgkey[item] is defined and mongodb_repository_gpgkey[item] != '' %} +baseurl={{ mongodb_repository[version_item] }} +{% if mongodb_repository_gpgkey[version_item] is defined and mongodb_repository_gpgkey[version_item] != '' %} gpgcheck=1 -gpgkey={{ mongodb_repository_gpgkey[item] }} +gpgkey={{ mongodb_repository_gpgkey[version_item] }} {% else %} gpgcheck=0 {% endif %}