Saltstack Official MongoDB Formula
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

88 lines
2.5KB

  1. {%- from "mongodb/map.jinja" import server with context %}
  2. {%- if server.get('enabled', False) %}
  3. mongodb_service_running:
  4. service.running:
  5. - name: {{ server.service }}
  6. - enable: true
  7. {%- if grains.get('noservices') %}
  8. - onlyif: /bin/false
  9. {%- endif %}
  10. {%- if server.members is defined and server.master == pillar.linux.system.name %}
  11. /var/tmp/mongodb_cluster.js:
  12. file.managed:
  13. - source: salt://mongodb/files/cluster.js
  14. - template: jinja
  15. - mode: 600
  16. - user: root
  17. - require:
  18. - service: mongodb_service_running
  19. mongodb_setup_cluster:
  20. cmd.run:
  21. - name: 'mongo localhost:27017 /var/tmp/mongodb_cluster.js && mongo localhost:27017 --quiet --eval "rs.conf()" | grep -i object -q'
  22. - unless: 'mongo localhost:27017 --quiet --eval "rs.conf()" | grep -i object -q'
  23. - require:
  24. - service: mongodb_service_running
  25. - file: /var/tmp/mongodb_cluster.js
  26. {%- endif %}
  27. {%- if server.members is not defined or server.master == pillar.linux.system.name %}
  28. {%- if server.authorization.get('enabled', False) %}
  29. /var/tmp/mongodb_user.js:
  30. file.managed:
  31. - source: salt://mongodb/files/user.js
  32. - template: jinja
  33. - mode: 600
  34. - user: root
  35. mongodb_change_root_password:
  36. cmd.run:
  37. - name: 'mongo localhost:27017/admin /var/tmp/mongodb_user.js && touch {{ server.lock_dir }}/mongodb_password_changed'
  38. {%- if grains.get('noservices') %}
  39. - onlyif: /bin/false
  40. {%- endif %}
  41. - require:
  42. - file: /var/tmp/mongodb_user.js
  43. - service: mongodb_service_running
  44. - creates: {{ server.lock_dir }}/mongodb_password_changed
  45. {%- for database_name, database in server.get('database', {}).iteritems() %}
  46. /var/tmp/mongodb_user_{{ database_name }}.js:
  47. file.managed:
  48. - source: salt://mongodb/files/user_role.js
  49. - template: jinja
  50. - mode: 600
  51. - user: root
  52. - defaults:
  53. database_name: {{ database_name }}
  54. mongodb_{{ database_name }}_fix_role:
  55. cmd.run:
  56. - 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'
  57. {%- if grains.get('noservices') %}
  58. - onlyif: /bin/false
  59. {%- endif %}
  60. - require:
  61. - file: /var/tmp/mongodb_user_{{ database_name }}.js
  62. - service: mongodb_service_running
  63. - creates: {{ server.lock_dir }}/mongodb_user_{{ database_name }}_created
  64. {%- if server.members is defined %}
  65. require:
  66. - cmd: mongodb_setup_cluster
  67. {%- endif %}
  68. {%- endfor %}
  69. {%- endif %}
  70. {%- endif %}
  71. {%- endif %}