<commit_before>{% from "mongodb/map.jinja" import mongodb with context %}
{% from "mongodb/map.jinja" import vagrant_host with context %}

include:
  - .service

copy_mongodb_key_file:
  file.managed:
    - name: {{ mongodb.cluster_key_file }}
    - contents: "{{ salt.pillar.get('mongodb:cluster_key') }}"
    - owner: mongodb
    - group: mongodb
    - mode: 0600

place_mongodb_config_file:
  file.managed:
    - name: /etc/{{ mongodb.service_name }}.conf
    - template: jinja
    - source: salt://mongodb/templates/mongodb.conf.j2
    - require:
      - file: copy_mongodb_key_file
    - watch_in:
      - service: mongodb_service_running

{% if 'mongodb_primary' in grains['roles'] %}

{% set replset_config = {'_id': salt.pillar.get('mongodb:replset_name', 'rs0'), 'members': []} %}
{% if salt.pillar.get("mongodb:VAGRANT", false) %}
{% do replset_config['members'].append({'_id': 0, 'host': vagrant_host + ':' + mongodb.port}) %}
{% else %}
{% set member_id = 0 %}
{% set eth0_index = 0 %}
{% for id, addrs in salt.mine.get('G@roles:mongodb and G@environment:{0}'.format(salt.grains.get('environment')), 'network.ip_addrs', expr_form='compound').items() %}
{% do replset_config['members'].append({'_id': member_id, 'host': addrs[eth0_index] }) %}
{% set member_id = member_id + 1 %}
{% endfor %}
{% endif %}

{% set MONGO_ADMIN_USER = salt.pillar.get("mongodb:admin_username") %}
{% set MONGO_ADMIN_PASSWORD = salt.pillar.get("mongodb:admin_password") %}
{% set mongo_cmd = '/usr/bin/mongo --port {0}'.format(mongodb.port) %}

place_root_user_script:
  file.managed:
    - name: /tmp/create_root.js<commit_msg>Moved jinja variables outside the if block for cases where a single mongodb is being used and not a cluster.<commit_after>{% from "mongodb/map.jinja" import mongodb with context %}
{% from "mongodb/map.jinja" import vagrant_host with context %}

include:
  - .service

copy_mongodb_key_file:
  file.managed:
    - name: {{ mongodb.cluster_key_file }}
    - contents: "{{ salt.pillar.get('mongodb:cluster_key') }}"
    - owner: mongodb
    - group: mongodb
    - mode: 0600

place_mongodb_config_file:
  file.managed:
    - name: /etc/{{ mongodb.service_name }}.conf
    - template: jinja
    - source: salt://mongodb/templates/mongodb.conf.j2
    - require:
      - file: copy_mongodb_key_file
    - watch_in:
      - service: mongodb_service_running

{% set MONGO_ADMIN_USER = salt.pillar.get("mongodb:admin_username") %}
{% set MONGO_ADMIN_PASSWORD = salt.pillar.get("mongodb:admin_password") %}
{% set mongo_cmd = '/usr/bin/mongo --port {0}'.format(mongodb.port) %}

{% if 'mongodb_primary' in grains['roles'] %}

{% set replset_config = {'_id': salt.pillar.get('mongodb:replset_name', 'rs0'), 'members': []} %}
{% if salt.pillar.get("mongodb:VAGRANT", false) %}
{% do replset_config['members'].append({'_id': 0, 'host': vagrant_host + ':' + mongodb.port}) %}
{% else %}
{% set member_id = 0 %}
{% set eth0_index = 0 %}
{% for id, addrs in salt.mine.get('G@roles:mongodb and G@environment:{0}'.format(salt.grains.get('environment')), 'network.ip_addrs', expr_form='compound').items() %}
{% do replset_config['members'].append({'_id': member_id, 'host': addrs[eth0_index] }) %}
{% set member_id = member_id + 1 %}
{% endfor %}
{% endif %}

place_root_user_script:
  file.managed:
    - name: /tmp/create_root.js
{'fraction_non_alphanumeric': 0.17802461723206245, 'fraction_numerical': 0.008405884118883218, 'mean_word_length': 4.348314606741573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '620782', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1194, 'n_words': 226}