diff --git a/roles/mongodb/tasks/configure-mongodb-auth.yml b/roles/mongodb/tasks/configure-mongodb-auth.yml index 9fdb5ea..79b0fe3 100644 --- a/roles/mongodb/tasks/configure-mongodb-auth.yml +++ b/roles/mongodb/tasks/configure-mongodb-auth.yml @@ -61,7 +61,7 @@ mode: '0400' # Execute the template to apply changes to the mongo.conf for auth -- name: Create MongoDB config file +- name: Create MongoDB config file (auth) ansible.builtin.template: src: mongod.conf.j2 dest: "{{ mongodb_conf_file }}" @@ -72,7 +72,11 @@ stage: "auth" - name: Start mongo - ansible.builtin.systemd: + ansible.builtin.service: name: mongod state: restarted enabled: true + register: mongod_service_result + until: mongod_service_result.status.ActiveState == "active" + retries: 15 + delay: 20 diff --git a/roles/mongodb/tasks/configure-mongodb-replicaset.yml b/roles/mongodb/tasks/configure-mongodb-replicaset.yml index ad07189..e4225e4 100644 --- a/roles/mongodb/tasks/configure-mongodb-replicaset.yml +++ b/roles/mongodb/tasks/configure-mongodb-replicaset.yml @@ -31,7 +31,7 @@ msg: "{{ mongodb_state }}" # Execute the template to apply changes to the mongo.conf for replication -- name: Create MongoDB config file +- name: Create MongoDB config file (replicaset) ansible.builtin.template: src: mongod.conf.j2 dest: "{{ mongodb_conf_file }}" @@ -43,10 +43,14 @@ stage: "replication" - name: Start mongo - ansible.builtin.systemd: + ansible.builtin.service: name: mongod state: restarted enabled: true + register: mongod_service_result + until: mongod_service_result.status.ActiveState == "active" + retries: 15 + delay: 20 when: not mongodb_state.replication_enabled - name: Set empty array of mongo servers diff --git a/roles/mongodb/tasks/install-mongodb.yml b/roles/mongodb/tasks/install-mongodb.yml index 151a154..837fee5 100644 --- a/roles/mongodb/tasks/install-mongodb.yml +++ b/roles/mongodb/tasks/install-mongodb.yml @@ -85,7 +85,7 @@ # users. That can not be done if all of these features are enabled. The # variable "stage" is used to provide this template context. When stage is # "initialize" the template will be forced to create a simple config. -- name: Create MongoDB config file +- name: Create MongoDB config file (initial) ansible.builtin.template: src: mongod.conf.j2 dest: "{{ mongodb_conf_file }}" @@ -97,10 +97,14 @@ tags: initialize_mongo_config - name: Start mongo - ansible.builtin.systemd: + ansible.builtin.service: name: mongod state: restarted enabled: true + register: mongod_service_result + until: mongod_service_result.status.ActiveState == "active" + retries: 15 + delay: 20 tags: initialize_mongo_config - name: Add users to database diff --git a/roles/mongodb/tasks/install-python.yml b/roles/mongodb/tasks/install-python.yml index 4c5a72a..34a9e33 100644 --- a/roles/mongodb/tasks/install-python.yml +++ b/roles/mongodb/tasks/install-python.yml @@ -12,11 +12,18 @@ python_executable: "{{ mongodb_python_executable }}" python_packages: "{{ mongodb_python_packages }}" + - name: Check if python virtual environment already exists + ansible.builtin.stat: + path: "{{ mongodb_python_venv }}" + register: mongodb_python_venv_check + - name: Setup python virtual environment ansible.builtin.command: chdir: "{{ mongodb_python_venv_root }}" cmd: "{{ mongodb_python_executable }} -m venv {{ mongodb_python_venv_name }}" - changed_when: true + register: mongodb_python_venv_result + changed_when: mongodb_python_venv_result.changed + when: not mongodb_python_venv_check.stat.exists - name: Install Python dependencies ansible.builtin.include_role: