From 3efddcf91d51dd55a7d322ec9e0f14f673da3d1a Mon Sep 17 00:00:00 2001 From: Sergei Antipov Date: Tue, 10 Feb 2015 18:45:13 +0600 Subject: [PATCH] Added a lot of new feautures --- tasks/configure.yml | 9 --------- tasks/mongodb.yml | 4 ++++ tasks/replication.yml | 29 +++++++++++++++++++++++++++++ templates/repset_init.js.j2 | 7 +++++++ vars/Debian.yml | 2 +- vars/Ubuntu.yml | 2 +- 6 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 tasks/replication.yml create mode 100644 templates/repset_init.js.j2 diff --git a/tasks/configure.yml b/tasks/configure.yml index 7a8fdbd..a7d8e61 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -17,15 +17,6 @@ - name: Configure logs file: state=file path={{ mongodb_conf_logpath }} owner={{mongodb_user}} group={{mongodb_user}} mode=0644 -- name: Create keyFile - copy: - dest: "{{ mongodb_conf_keyFile }}" - content: "{{ mongodb_keyfile_content }}" - owner: "{{ mongodb_user }}" - group: "root" - mode: 0600 - when: mongodb_conf_replSet != "" - - name: Run mongoshell commands command: mongo {{ item.key }} --eval "{{ item.value|join('\n') }}" with_dict: mongodb_shell diff --git a/tasks/mongodb.yml b/tasks/mongodb.yml index 99cb206..2850ff5 100644 --- a/tasks/mongodb.yml +++ b/tasks/mongodb.yml @@ -12,5 +12,9 @@ - include: authorization.yml when: mongodb_conf_auth == "yes" +- meta: flush handlers +- include: replication.yml + when: mongodb_conf_replSet != "" + - include: mms-agent.yml when: mongodb_mms_api_key != "" diff --git a/tasks/replication.yml b/tasks/replication.yml new file mode 100644 index 0000000..3e76a6f --- /dev/null +++ b/tasks/replication.yml @@ -0,0 +1,29 @@ +--- + +- name: Create keyFile + copy: + dest: "{{ mongodb_conf_keyFile }}" + content: "{{ mongodb_keyfile_content }}" + owner: "{{ mongodb_user }}" + group: "root" + mode: 0600 + +- name: Check replication status + shell: "{{ item }}" + register: replication_status + when: mongodb_conf_auth == "yes" + with_items: + - /usr/bin/mongo --username {{ mongodb_root_admin_name }} --password {{ mongodb_root_admin_password }} admin --eval 'printjson(rs.status())' | tail -n +3 + - /usr/bin/mongo admin --eval 'printjson(rs.status())' | tail -n +3 + changed_when: false + +- debug: + msg: "{{ (replication_status.results[0].stdout|from_json).errmsg }}" + +- name: Create the file to initialize the mongod replica set + template: src=repset_init.js.j2 dest=/tmp/repset_init.js + when: mongodb_conf_auth == "yes" and (replication_status.results[0].stdout|from_json).errmsg | search("EMPTYCONFIG") + +- name: Initialize replica set + shell: /usr/bin/mongo --username {{ mongodb_root_admin_name }} --password {{ mongodb_root_admin_password }} admin /tmp/repset_init.js + when: mongodb_conf_auth == "yes" and (replication_status.results[0].stdout|from_json).errmsg | search("EMPTYCONFIG") diff --git a/templates/repset_init.js.j2 b/templates/repset_init.js.j2 new file mode 100644 index 0000000..b0499bc --- /dev/null +++ b/templates/repset_init.js.j2 @@ -0,0 +1,7 @@ +rs.initiate() +sleep(5000) +{% for host in groups['replication_servers'] %} +rs.add("{{ host }}:{{ mongodb_conf_port }}") +sleep(8000) +{% endfor %} +printjson(rs.status()) diff --git a/vars/Debian.yml b/vars/Debian.yml index b01e93f..7ac9326 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -1,3 +1,3 @@ --- -mongodb_repository: deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen +mongodb_repository: deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen diff --git a/vars/Ubuntu.yml b/vars/Ubuntu.yml index 7ac9326..b01e93f 100644 --- a/vars/Ubuntu.yml +++ b/vars/Ubuntu.yml @@ -1,3 +1,3 @@ --- -mongodb_repository: deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen +mongodb_repository: deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen