From 77c55d557b37288937b6b04a1568ec2bd69ec7b3 Mon Sep 17 00:00:00 2001 From: Sergei Antipov Date: Sun, 17 Apr 2016 23:18:31 +0600 Subject: [PATCH] Fixed problem with concurrency race --- .travis.yml | 2 +- tasks/main.yml | 27 +++++++++++++++++++++++---- tests/hosts | 4 ++-- tests/site.yml | 11 +++++++++-- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3bf2358c..6dfc25a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -66,7 +66,7 @@ script: # Test 3 - > - sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo + sudo ansible-playbook -i tests/hosts tests/site.yml -e target=mongo -e mongodb_version=${MONGODB_VERSION} -e mongodb_replication_replset='testrs' # Idempotence test - > diff --git a/tasks/main.yml b/tasks/main.yml index 1886ef1c..aaf40857 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -42,7 +42,7 @@ and mongodb_user_admin_check.rc != 0 ) tags: [mongodb] -- name: create normal users +- name: create normal users with replicaset mongodb_user: database: "{{ item.database }}" name: "{{ item.name }}" @@ -51,13 +51,32 @@ roles: "{{ item.roles }}" login_user: "{{ mongodb_user_admin_name }}" login_password: "{{ mongodb_user_admin_password }}" - login_port: "{{ mongodb_net_port }}" - login_database: "admin" + login_port: "{{ mongodb_login_port|default(27017) }}" + login_host: "{{ mongodb_login_host|default('localhost') }}" with_items: - "{{ mongodb_users | default([]) }}" - when: mongodb_security_authorization == 'enabled' + when: ( mongodb_replication_replset + and mongodb_replication_replset != '' + and mongodb_security_authorization == 'enabled' + and mongodb_master is defined and mongodb_master ) tags: [mongodb] +- name: create normal users without replicaset + mongodb_user: + database: "{{ item.database }}" + name: "{{ item.name }}" + password: "{{ item.password }}" + update_password: "{{ mongodb_user_update_password }}" + roles: "{{ item.roles }}" + login_user: "{{ mongodb_user_admin_name }}" + login_password: "{{ mongodb_user_admin_password }}" + login_port: "{{ mongodb_net_port }}" + with_items: + - "{{ mongodb_users | default([]) }}" + when: ( mongodb_security_authorization == 'enabled' + and (not mongodb_replication_replset + or mongodb_replication_replset == '') ) + tags: [mongodb] - name: Include MMS Agent configuration include: mms-agent.yml diff --git a/tests/hosts b/tests/hosts index 0601b60d..0f930081 100644 --- a/tests/hosts +++ b/tests/hosts @@ -4,10 +4,10 @@ localhost ansible_connection=local ansible_python_interpreter=python2 [mongo_master] mongo1 ansible_connection=docker ansible_python_interpreter=python2 -[mongo_slave] +[mongo_replicas] mongo2 ansible_connection=docker ansible_python_interpreter=python2 mongo3 ansible_connection=docker ansible_python_interpreter=python2 [mongo:children] mongo_master -mongo_slave \ No newline at end of file +mongo_replicas \ No newline at end of file diff --git a/tests/site.yml b/tests/site.yml index 9af01d9d..1ab41628 100644 --- a/tests/site.yml +++ b/tests/site.yml @@ -21,5 +21,12 @@ gather_facts: yes roles: - role: greendayonfire.mongodb - when: "'mongo' in group_names" - + when: "'mongo_master' in group_names" + +- hosts: "{{ target }}" + become: no + gather_facts: yes + roles: + - role: greendayonfire.mongodb + when: "'mongo_replicas' in group_names" +