Skip to content

Add wait until active to mongod startup #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions roles/mongodb/tasks/configure-mongodb-auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -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
8 changes: 6 additions & 2 deletions roles/mongodb/tasks/configure-mongodb-replicaset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions roles/mongodb/tasks/install-mongodb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion roles/mongodb/tasks/install-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading