From efe0c3269ba18be5c0fe5966e20146feb16c2bca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 1 Aug 2019 14:12:39 -0400 Subject: [PATCH] configure prod MongoDB replicate set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- ansible/{main.yml => dev.yml} | 4 ++-- ansible/group_vars/db.prod.yml | 7 ++++++- ansible/host_vars/node-01.us-east-1a.db.prod | 4 ++++ ansible/prod.yml | 11 +++++++++++ ansible/requirements.yml | 2 ++ 5 files changed, 25 insertions(+), 3 deletions(-) rename ansible/{main.yml => dev.yml} (84%) create mode 100644 ansible/host_vars/node-01.us-east-1a.db.prod create mode 100644 ansible/prod.yml diff --git a/ansible/main.yml b/ansible/dev.yml similarity index 84% rename from ansible/main.yml rename to ansible/dev.yml index 9729542..a9043f6 100644 --- a/ansible/main.yml +++ b/ansible/dev.yml @@ -1,6 +1,6 @@ --- -- name: Configure MongoDB - hosts: mongodb +- name: Configure MongoDB dev cluster + hosts: db.dev roles: - mongodb-firewall - mongodb-setup diff --git a/ansible/group_vars/db.prod.yml b/ansible/group_vars/db.prod.yml index 72a4535..293abf3 100644 --- a/ansible/group_vars/db.prod.yml +++ b/ansible/group_vars/db.prod.yml @@ -1,6 +1,7 @@ --- # versions mongodb_version: "4.0" +# Fixes: https://github.com/ansible/ansible/issues/44970 mongodb_pymongo_pip_version: 3.8.0 # listening address & port @@ -33,11 +34,15 @@ mongodb_oplog_users: mongodb_login_host_vars: '{{ hostvars[groups["db.prod"][0]] }}' mongodb_login_host: '{{ mongodb_login_host_vars["dns_entry"] }}' -# TODO generate this dynamically mongodb_replication_params: + - host_name: '{{ hostvars[groups["db.prod"][0]].dns_entry }}' - host_name: '{{ hostvars[groups["db.prod"][1]].dns_entry }}' - host_name: '{{ hostvars[groups["db.prod"][2]].dns_entry }}' +# avoid having to auth on localhost +mongodb_set_parameters: + enableLocalhostAuthBypass: "true" + # backups auth mongodb_backup_db_name: '{{ mongodb_users[0].database }}' mongodb_backup_db_user: '{{ mongodb_users[0].name }}' diff --git a/ansible/host_vars/node-01.us-east-1a.db.prod b/ansible/host_vars/node-01.us-east-1a.db.prod new file mode 100644 index 0000000..c05d65b --- /dev/null +++ b/ansible/host_vars/node-01.us-east-1a.db.prod @@ -0,0 +1,4 @@ +--- +# use this variable for replica set init only +# or when master is moved from initial master node +mongodb_master: true diff --git a/ansible/prod.yml b/ansible/prod.yml new file mode 100644 index 0000000..b2aa839 --- /dev/null +++ b/ansible/prod.yml @@ -0,0 +1,11 @@ +--- +- name: Configure MongoDB prod cluster + hosts: db.prod + roles: + - mongodb-firewall + - mongodb-setup + - mongodb-backups + post_tasks: + - name: MongoDB URI string + debug: + msg: 'mongodb://{{ mongodb_users[0].name }}:{{ mongodb_users[0].password }}@{{ dns_entry }}:{{ mongodb_net_port }}/{{ mongodb_users[0].database }}' diff --git a/ansible/requirements.yml b/ansible/requirements.yml index 3185b8a..cce0f34 100644 --- a/ansible/requirements.yml +++ b/ansible/requirements.yml @@ -19,6 +19,8 @@ src: git@github.com:status-im/infra-role-s3cmd-backup.git scm: git +# WARNING: Fails if python3 is the default +# Details: - name: mongodb-setup src: https://github.com/UnderGreen/ansible-role-mongodb.git scm: git