Browse Source

Merge pull request #5 from Martin819/master

Optimize 'noservices' condition
pull/6/head
Filip Pytloun 7 years ago
parent
commit
0c8b5690c4
1 changed files with 9 additions and 18 deletions
  1. +9
    -18
      mongodb/server.sls

+ 9
- 18
mongodb/server.sls View File

@@ -21,10 +21,8 @@ mongodb_packages:
- user: mongodb
- require:
- pkg: mongodb_packages
{%- if not grains.get('noservices', False) %}
- watch_in:
- service: mongodb_service
{%- endif %}

{%- endif %}

@@ -32,20 +30,19 @@ mongodb_packages:
file.directory:
- makedirs: true

{%- if not grains.get('noservices', False) %}

mongodb_service:
service.running:
- name: {{ server.service }}
- enable: true
{%- if grains.get('noservices') %}
- onlyif: /bin/false
{%- endif %}
- require:
- file: {{ server.lock_dir }}
- pkg: mongodb_packages
- watch:
- file: /etc/mongodb.conf

{%- endif %}

{%- if server.members is not defined or server.master == pillar.linux.system.name %}
{# We are not a cluster or we are master #}

@@ -56,18 +53,17 @@ mongodb_service:
- mode: 600
- user: root

{%- if not grains.get('noservices', False) %}

mongodb_change_root_password:
cmd.run:
- name: 'mongo localhost:27017/admin /var/tmp/mongodb_user.js && touch {{ server.lock_dir }}/mongodb_password_changed'
{%- if grains.get('noservices') %}
- onlyif: /bin/false
{%- endif %}
- require:
- file: /var/tmp/mongodb_user.js
- service: mongodb_service
- creates: {{ server.lock_dir }}/mongodb_password_changed

{%- endif %}

{%- for database_name, database in server.get('database', {}).iteritems() %}

/var/tmp/mongodb_user_{{ database_name }}.js:
@@ -79,24 +75,21 @@ mongodb_change_root_password:
- defaults:
database_name: {{ database_name }}

{%- if not grains.get('noservices', False) %}

mongodb_{{ database_name }}_fix_role:
cmd.run:
- name: 'mongo localhost:27017/admin -u admin -p {{ server.admin.password }} /var/tmp/mongodb_user_{{ database_name }}.js && touch {{ server.lock_dir }}/mongodb_user_{{ database_name }}_created'
{%- if grains.get('noservices') %}
- onlyif: /bin/false
{%- endif %}
- require:
- file: /var/tmp/mongodb_user_{{ database_name }}.js
{%- if not grains.get('noservices', False) %}
- service: mongodb_service
{%- endif%}
- creates: {{ server.lock_dir }}/mongodb_user_{{ database_name }}_created
{%- if server.members is defined %}
require:
- cmd: mongodb_setup_cluster
{%- endif %}

{%- endif %}

{%- endfor %}

{%- if server.members is defined %}
@@ -113,9 +106,7 @@ mongodb_setup_cluster:
- name: 'mongo localhost:27017/admin /var/tmp/mongodb_cluster.js && mongo localhost:27017/admin --quiet --eval "rs.conf()" | grep object -q'
- unless: 'mongo localhost:27017/admin -u admin -p {{ server.admin.password }} --quiet --eval "rs.conf()" | grep object -q'
- require:
{%- if not grains.get('noservices', False) %}
- service: mongodb_service
{%- endif %}
- file: /var/tmp/mongodb_cluster.js
- require_in:
- cmd: mongodb_change_root_password

Loading…
Cancel
Save