Skip to content
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

Rocket.Chat: Initialize with js #347

Merged
merged 1 commit into from
Mar 12, 2024
Merged
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
45 changes: 20 additions & 25 deletions roles/rocketchat/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,13 @@
# GNU General Public License v3.0 #
#########################################################################
---
- name: MongoDB Role
ansible.builtin.include_role:
name: mongodb
vars:
mongodb_instances: ["rocketchat_db"]
mongodb_docker_image_tag: "6"
mongodb_docker_commands: ["mongod --oplogSize 128 --replSet rs0"]

- name: Add DNS record
ansible.builtin.include_tasks: "{{ resources_tasks_path }}/dns/tasker.yml"
vars:
dns_record: "{{ lookup('vars', role_name + '_dns_record') }}"
dns_zone: "{{ lookup('vars', role_name + '_dns_zone') }}"
dns_proxy: "{{ lookup('vars', role_name + '_dns_proxy') }}"

- name: Remove existing Docker container
ansible.builtin.include_tasks: "{{ resources_tasks_path }}/docker/remove_docker_container.yml"

- name: Create directories
ansible.builtin.file:
path: "{{ item }}"
Expand All @@ -34,20 +23,26 @@
mode: "0775"
with_items: "{{ lookup('vars', role_name + '_paths_folders_list') }}"

# this container's job is just to run the command to initialize the replica set.
# it will run the command and will later be removed automatically
- name: Initialize MongoDB Replica Set
community.docker.docker_container:
name: "rocketchat-mongo-init-replica"
image: "mongo:6"
command: 'bash -c "for i in `seq 1 30`; do mongosh rocketchat_db/rocketchat --eval \"rs.initiate({ _id: ''rs0'', members: [ { _id: 0, host: ''localhost:27017'' } ]})\" && s=$$? && break || s=$$?; echo \"Tried $$i times. Waiting 5 secs...\"; sleep 5; done; (exit $$s)"'
networks:
- name: saltbox
comparisons:
'*': ignore
auto_remove: yes
state: started
pull: true
- name: "RocketChat | Import init-mongo.js"
ansible.builtin.template:
src: init-mongo.js
dest: '{{ rocketchat_paths_location }}/init-mongo.js'
owner: "{{ user.name }}"
group: "{{ user.name }}"
mode: "0775"
force: yes

- name: MongoDB Role
ansible.builtin.include_role:
name: mongodb
vars:
mongodb_instances: ["rocketchat_db"]
mongodb_docker_image_tag: "6"
mongodb_docker_commands: ["mongod --oplogSize 128 --replSet rs0"]
mongodb_docker_volumes_custom: ["{{ rocketchat_paths_location }}/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro"]

- name: Remove existing Docker container
ansible.builtin.include_tasks: "{{ resources_tasks_path }}/docker/remove_docker_container.yml"

- name: Create Docker container
ansible.builtin.include_tasks: "{{ resources_tasks_path }}/docker/create_docker_container.yml"
9 changes: 9 additions & 0 deletions roles/rocketchat/templates/init-mongo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rs.initiate(
{
_id: "rs0",
version: 1,
members: [
{ _id: 0, host : "localhost:27017" }
]
}
)