Skip to content

Commit

Permalink
fix: default value for no_log for dev env
Browse files Browse the repository at this point in the history
  • Loading branch information
Regzox committed Dec 7, 2023
1 parent b9c809d commit 459165a
Show file tree
Hide file tree
Showing 22 changed files with 249 additions and 275 deletions.
1 change: 0 additions & 1 deletion deployment/environments/group_vars/all/ansible_options.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

packages_install_retries_number: 10
packages_install_retries_delay: 10
hide_passwords_during_deploy: true # false for testing purpose
6 changes: 2 additions & 4 deletions deployment/roles/init_app_bdd/tasks/check_auth.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---

- name: Check if authent is enabled
command: "mongosh {{ ip_service }}:{{ mongodb.mongod_port }}/admin -u {{ mongodb.admin.user }} -p {{ mongodb.admin.password }} --quiet --eval 'db.help()'"
register: mongo_authent_enabled
failed_when: false
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
tags:
- update_mongodb_configuration

Expand All @@ -29,5 +28,4 @@
set_fact:
mongo_credentials: " -u {{ mongodb.admin.user }} -p {{ mongodb.admin.password }} --quiet"
when: "mongo_authent_enabled.rc == 0"
no_log: "{{ hide_passwords_during_deploy }}"

no_log: "{{ hide_passwords_during_deploy | default(true) }}"
2 changes: 1 addition & 1 deletion deployment/roles/init_app_bdd/tasks/referential.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

- name: Load referential scripts in database
command: "mongosh {{ ip_service }}:{{ mongodb.mongod_port }}/admin {{ mongo_credentials }} {{ vitamui_defaults.folder.root_path | default('/vitamui') }}/app/mongod/scripts/referential/{{ item | basename | regex_replace('\\.j2$') }}"
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
with_fileglob:
- "{{ role_path }}/templates/referential/*"
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

- name: Load archive search scripts in database
command: "mongosh {{ ip_service }}:{{ mongodb.mongod_port }}/admin {{ mongo_credentials }} {{ vitamui_defaults.folder.root_path | default('/vitamui') }}/app/mongod/scripts/archive-search/{{ item | basename | regex_replace('\\.j2$') }}"
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
with_fileglob:
- "{{ role_path }}/templates/archive-search/*"
tags:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---

- name: Check if authent is enabled
command: "mongosh {{ ip_service }}:{{ mongodb.mongod_port }}/admin -u {{ mongodb.admin.user }} -p {{ mongodb.admin.password }} --quiet --eval 'db.help()'"
register: mongo_authent_enabled
failed_when: false
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
tags:
- update_mongodb_configuration

Expand All @@ -29,5 +28,4 @@
set_fact:
mongo_credentials: " -u {{ mongodb.admin.user }} -p {{ mongodb.admin.password }} --quiet"
when: "mongo_authent_enabled.rc == 0"
no_log: "{{ hide_passwords_during_deploy }}"

no_log: "{{ hide_passwords_during_deploy | default(true) }}"
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---

- name: Check if authent is enabled
command: "mongosh {{ ip_service }}:{{ mongodb.mongod_port }}/admin -u {{ mongodb.admin.user }} -p {{ mongodb.admin.password }} --quiet --eval 'db.help()'"
register: mongo_authent_enabled
failed_when: false
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
tags:
- update_mongodb_configuration

Expand All @@ -29,5 +28,4 @@
set_fact:
mongo_credentials: " -u {{ mongodb.admin.user }} -p {{ mongodb.admin.password }} --quiet"
when: "mongo_authent_enabled.rc == 0"
no_log: "{{ hide_passwords_during_deploy }}"

no_log: "{{ hide_passwords_during_deploy | default(true) }}"
2 changes: 1 addition & 1 deletion deployment/roles/init_ingest_app_bdd/tasks/ingest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

- name: Load ingest scripts in database
command: "mongosh {{ ip_service }}:{{ mongodb.mongod_port }}/admin {{ mongo_credentials }} {{ vitamui_defaults.folder.root_path | default('/vitamui') }}/app/mongod/scripts/ingest/{{ item | basename | regex_replace('\\.j2$') }}"
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
with_fileglob:
- "{{ role_path }}/templates/ingest/*"
tags:
Expand Down
6 changes: 2 additions & 4 deletions deployment/roles/mongo/tasks/check_auth.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---

- name: Check if authent is enabled
command: "mongosh {{ ip_service }}:{{ mongodb.mongod_port }}/admin -u {{ mongodb.admin.user }} -p {{ mongodb.admin.password }} --quiet --eval 'db.help()'"
register: mongo_authent_enabled
failed_when: false
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
tags: update_mongodb_configuration

- name: Set mongo_no_auth fact to true
Expand All @@ -20,6 +19,5 @@
mongo_credentials: "-u {{ mongodb.admin.user }} -p {{ mongodb.admin.password }}"
mongo_no_auth: false
when: "mongo_authent_enabled.rc == 0"
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
tags: update_mongodb_configuration

5 changes: 2 additions & 3 deletions deployment/roles/mongo_backup/tasks/backup_collection.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---

- name: mongo dump collection
command: "mongodump --host {{ ip_service }} --db {{db}} --collection {{inner_item}} {{mongo_credentials}} --gzip --out {{mongo_dump_folder}}"
with_items:
- "{{collections}}"
- "{{collections}}"
loop_control:
loop_var: inner_item
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
ignore_errors: yes
3 changes: 1 addition & 2 deletions deployment/roles/mongo_backup/tasks/backup_db.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---

- name: "mongo dump db ({{db}})"
command: "mongodump --host {{ ip_service }} --db {{db}} {{mongo_credentials}} --gzip --out {{mongo_dump_folder}}"
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
ignore_errors: yes
5 changes: 2 additions & 3 deletions deployment/roles/mongo_configure/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
---

- name: Set mongo connection & credentials
set_fact:
mongo_connection: "--host {{ ip_service }} --port {{ mongodb.mongod_port }} --quiet"
mongo_credentials: "-u {{ mongodb.admin.user }} -p {{ mongodb.admin.password }}"
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
tags: update_mongodb_configuration

# Detect if authentication is enabled
- name: Verify if authent is enabled
command: "mongosh {{ mongo_connection }} {{ mongo_credentials }} --eval 'db.help();'"
register: mongo_authent_enabled
failed_when: false
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
tags: update_mongodb_configuration

- name: Disable mongo credentials as authent is not enabled
Expand Down
6 changes: 3 additions & 3 deletions deployment/roles/mongo_init/tasks/check_auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
command: "mongosh mongodb://{{ mongod_uri }}/admin?replicaSet={{ mongod_replicaset_name }} -u {{ mongodb.admin.user }} -p {{ mongodb.admin.password }} --quiet --eval 'db.help()'"
register: mongo_authent_enabled
failed_when: false
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"

- name: Set mongo_no_auth fact to true
set_fact:
Expand All @@ -20,7 +20,7 @@

- block:
- name: Load script in database (docker)
shell: "docker exec --tty {{ mongodb.docker.image_name }} /bin/bash -c \"mongosh mongodb://{{ mongod_uri }}/admin?replicaSet={{ mongod_replicaset_name }} -u {{ mongodb.admin.user }} -p {{ mongodb.admin.password }} --quiet --eval 'db.help()'\""
shell: 'docker exec --tty {{ mongodb.docker.image_name }} /bin/bash -c "mongosh mongodb://{{ mongod_uri }}/admin?replicaSet={{ mongod_replicaset_name }} -u {{ mongodb.admin.user }} -p {{ mongodb.admin.password }} --quiet --eval ''db.help()''"'

failed_when: false
register: mongo_authent_enabled
Expand All @@ -36,4 +36,4 @@
set_fact:
mongo_credentials: " -u {{ mongodb.admin.user }} -p {{ mongodb.admin.password }} --authenticationDatabase {{ mongodb.admin.db }} "
when: not mongo_no_auth
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
206 changes: 102 additions & 104 deletions deployment/roles/mongo_init/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,109 +1,107 @@
---

- block:

- fail: msg="Variable '{{ mongod_source_template_dir }}' is not defined"
when: mongod_source_template_dir is undefined

- name: Compute list of mongo nodes
set_fact:
mongo_nodes: "{{ mongo_nodes | default([]) + [ hostvars[item]['ip_service'] + ':'+ mongodb.mongod_port | string ] }}"
loop: "{{ groups['hosts_vitamui_mongod'] }}"

- name: Set Mongo URI
set_fact:
mongod_uri: "{{ mongo_nodes| join(',') }}"

- name: Set mongod_output_dir_entry_point
set_fact:
mongod_output_dir_entry_point: "{{ vitamui_defaults.folder.root_path | default('/vitamui') }}/app/mongod/"

- import_tasks: check_auth.yml

- name: Initialize directory if it doesn't exist.
file:
path: "{{ mongod_output_dir_entry_point }}"
state: directory

- name: "Clean directory {{ mongod_output_dir_entry_point }}"
shell: "rm -Rf {{ mongod_output_dir_entry_point }}/*"

# We sort directories by theirs versions
- name: List script files versions in the directory {{ mongod_source_template_dir }}
delegate_to: localhost
shell:
cmd: find * -maxdepth 1 -type d | sort -V
chdir: "{{ mongod_source_template_dir }}"
register: versions

# For each version, we apply a second sort on the index of the script file.
- name: List script files in the directory {{ mongod_source_template_dir }}
delegate_to: localhost
shell:
cmd: find {{ version }}/* -type f -print | sort -V -t '_' -k1
chdir: "{{ mongod_source_template_dir }}"
register: output
loop: "{{ versions.stdout_lines }}"
loop_control:
loop_var: version

- name: "Compute file scripts"
delegate_to: localhost
set_fact:
mongod_files: "{{ (mongod_files| default([])) + item.stdout_lines }}"
loop: "{{ output.results }}"

# We apply regex for included and excluded files in order to compute the eligible scripts.
- name: Compute list of excluded files
delegate_to: localhost
set_fact:
mongod_excluded_files : "{{ (mongod_excluded_files| default([])) + [ item.0 ] }}"
when: item.0 is not match(item.1) or item.0 is match(item.2)
with_nested:
- "{{ mongod_files }}"
- "{{ mongodb.included_scripts }}"
- "{{ mongodb.excluded_scripts }}"

- name: Compute list of eligible files
delegate_to: localhost
set_fact:
mongod_eligible_files : "{{ (mongod_eligible_files| default([])) + [ {'name': item, 'version': item | regex_replace('^(.+)/(.+)$', '\\1') ,'finalname': 'vitamui_' + item | regex_replace('/', '_') | basename | regex_replace('\\.j2$')} ] }}"
loop: "{{ mongod_files | difference(mongod_excluded_files| default([])) }}"

# We generate scripts and upload on remote host
- name: Compute and copy script files
template:
src: "{{ mongod_source_template_dir }}/{{ item.name }}"
dest: "{{ mongod_output_dir_entry_point }}/{{ item.finalname }}"
owner: "{{ vitamui_defaults.users.vitamuidb | default('vitamuidb') }}"
group: "{{ vitamui_defaults.users.group | default('vitamui') }}"
mode: 0755
loop: "{{ mongod_eligible_files | unique }}"

- name: "Prepare file"
include_tasks: "prepare_script.yml"
when: mongodb.versioning is defined and mongodb.versioning.enable
loop: "{{ mongod_eligible_files | unique }}"
loop_control:
loop_var: mongo_file

- name: Compute main script file
template:
src: "main_script.js.j2"
dest: "{{ mongod_output_dir_entry_point }}/main_script.js"
owner: "{{ vitamui_defaults.users.vitamuidb | default('vitamuidb') }}"
group: "{{ vitamui_defaults.users.group | default('vitamui') }}"
mode: 0755

- name: Load script in database
shell: "mongosh mongodb://{{ mongod_uri }}/admin {{ mongo_credentials }} --quiet --file {{ mongod_output_dir_entry_point }}/main_script.js"
no_log: "{{ hide_passwords_during_deploy }}"
when: mongodb.docker is not defined or not mongodb.docker.enable

- name: Load script in database test (docker)
command: "docker exec --tty {{ mongodb.docker.image_name }} /bin/bash -c \"mongosh mongodb://{{ mongod_uri }}/admin {{ mongo_credentials }} --quiet --file {{ mongodb.docker.internal_dir}}/app/mongod/main_script.js\""
no_log: "{{ hide_passwords_during_deploy }}"
when: mongodb.docker is defined and mongodb.docker.enable
- fail: msg="Variable '{{ mongod_source_template_dir }}' is not defined"
when: mongod_source_template_dir is undefined

- name: Compute list of mongo nodes
set_fact:
mongo_nodes: "{{ mongo_nodes | default([]) + [ hostvars[item]['ip_service'] + ':'+ mongodb.mongod_port | string ] }}"
loop: "{{ groups['hosts_vitamui_mongod'] }}"

- name: Set Mongo URI
set_fact:
mongod_uri: "{{ mongo_nodes| join(',') }}"

- name: Set mongod_output_dir_entry_point
set_fact:
mongod_output_dir_entry_point: "{{ vitamui_defaults.folder.root_path | default('/vitamui') }}/app/mongod/"

- import_tasks: check_auth.yml

- name: Initialize directory if it doesn't exist.
file:
path: "{{ mongod_output_dir_entry_point }}"
state: directory

- name: "Clean directory {{ mongod_output_dir_entry_point }}"
shell: "rm -Rf {{ mongod_output_dir_entry_point }}/*"

# We sort directories by theirs versions
- name: List script files versions in the directory {{ mongod_source_template_dir }}
delegate_to: localhost
shell:
cmd: find * -maxdepth 1 -type d | sort -V
chdir: "{{ mongod_source_template_dir }}"
register: versions

# For each version, we apply a second sort on the index of the script file.
- name: List script files in the directory {{ mongod_source_template_dir }}
delegate_to: localhost
shell:
cmd: find {{ version }}/* -type f -print | sort -V -t '_' -k1
chdir: "{{ mongod_source_template_dir }}"
register: output
loop: "{{ versions.stdout_lines }}"
loop_control:
loop_var: version

- name: "Compute file scripts"
delegate_to: localhost
set_fact:
mongod_files: "{{ (mongod_files| default([])) + item.stdout_lines }}"
loop: "{{ output.results }}"

# We apply regex for included and excluded files in order to compute the eligible scripts.
- name: Compute list of excluded files
delegate_to: localhost
set_fact:
mongod_excluded_files: "{{ (mongod_excluded_files| default([])) + [ item.0 ] }}"
when: item.0 is not match(item.1) or item.0 is match(item.2)
with_nested:
- "{{ mongod_files }}"
- "{{ mongodb.included_scripts }}"
- "{{ mongodb.excluded_scripts }}"

- name: Compute list of eligible files
delegate_to: localhost
set_fact:
mongod_eligible_files: "{{ (mongod_eligible_files| default([])) + [ {'name': item, 'version': item | regex_replace('^(.+)/(.+)$', '\\1') ,'finalname': 'vitamui_' + item | regex_replace('/', '_') | basename | regex_replace('\\.j2$')} ] }}"
loop: "{{ mongod_files | difference(mongod_excluded_files| default([])) }}"

# We generate scripts and upload on remote host
- name: Compute and copy script files
template:
src: "{{ mongod_source_template_dir }}/{{ item.name }}"
dest: "{{ mongod_output_dir_entry_point }}/{{ item.finalname }}"
owner: "{{ vitamui_defaults.users.vitamuidb | default('vitamuidb') }}"
group: "{{ vitamui_defaults.users.group | default('vitamui') }}"
mode: 0755
loop: "{{ mongod_eligible_files | unique }}"

- name: "Prepare file"
include_tasks: "prepare_script.yml"
when: mongodb.versioning is defined and mongodb.versioning.enable
loop: "{{ mongod_eligible_files | unique }}"
loop_control:
loop_var: mongo_file

- name: Compute main script file
template:
src: "main_script.js.j2"
dest: "{{ mongod_output_dir_entry_point }}/main_script.js"
owner: "{{ vitamui_defaults.users.vitamuidb | default('vitamuidb') }}"
group: "{{ vitamui_defaults.users.group | default('vitamui') }}"
mode: 0755

- name: Load script in database
shell: "mongosh mongodb://{{ mongod_uri }}/admin {{ mongo_credentials }} --quiet --file {{ mongod_output_dir_entry_point }}/main_script.js"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
when: mongodb.docker is not defined or not mongodb.docker.enable

- name: Load script in database test (docker)
command: 'docker exec --tty {{ mongodb.docker.image_name }} /bin/bash -c "mongosh mongodb://{{ mongod_uri }}/admin {{ mongo_credentials }} --quiet --file {{ mongodb.docker.internal_dir}}/app/mongod/main_script.js"'
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
when: mongodb.docker is defined and mongodb.docker.enable

# - name: "Execute file"
# include_tasks: "execute_script.yml"
Expand Down
3 changes: 1 addition & 2 deletions deployment/roles/mongo_restore/tasks/restore_collection.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
---

- name: Restore each collection for {{db}}
command: "mongorestore --host {{ ip_service }} --db {{db}} --collection {{inner_item}} {{mongo_credentials}} --gzip {{mongo_dump_folder}}/{{db}}/{{inner_item}}.bson.gz"
with_items: "{{collections}}"
loop_control:
loop_var: inner_item
no_log: "{{ hide_passwords_during_deploy }}"
no_log: "{{ hide_passwords_during_deploy | default(true) }}"
ignore_errors: yes
Loading

0 comments on commit 459165a

Please sign in to comment.