Saltstack Official MongoDB Formula
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

119 lines
3.0KB

  1. {%- from "mongodb/map.jinja" import server with context %}
  2. {%- if server.enabled %}
  3. mongodb_packages:
  4. pkg.installed:
  5. - names: {{ server.pkgs }}
  6. /etc/mongodb.conf:
  7. file.managed:
  8. - source: salt://mongodb/files/mongodb.conf
  9. - template: jinja
  10. - require:
  11. - pkg: mongodb_packages
  12. {%- if server.shared_key is defined %}
  13. /etc/mongodb.key:
  14. file.managed:
  15. - contents_pillar: mongodb:server:shared_key
  16. - mode: 600
  17. - user: mongodb
  18. - require:
  19. - pkg: mongodb_packages
  20. - watch_in:
  21. - service: mongodb_service
  22. {%- endif %}
  23. {{ server.lock_dir }}:
  24. file.directory:
  25. - makedirs: true
  26. mongodb_service:
  27. service.running:
  28. - name: {{ server.service }}
  29. - enable: true
  30. {%- if grains.get('noservices') %}
  31. - onlyif: /bin/false
  32. {%- endif %}
  33. - require:
  34. - file: {{ server.lock_dir }}
  35. - pkg: mongodb_packages
  36. - watch:
  37. - file: /etc/mongodb.conf
  38. {%- if server.members is not defined or server.master == pillar.linux.system.name %}
  39. {# We are not a cluster or we are master #}
  40. /var/tmp/mongodb_user.js:
  41. file.managed:
  42. - source: salt://mongodb/files/user.js
  43. - template: jinja
  44. - mode: 600
  45. - user: root
  46. mongodb_change_root_password:
  47. cmd.run:
  48. - name: 'mongo localhost:27017/admin /var/tmp/mongodb_user.js && touch {{ server.lock_dir }}/mongodb_password_changed'
  49. {%- if grains.get('noservices') %}
  50. - onlyif: /bin/false
  51. {%- endif %}
  52. - require:
  53. - file: /var/tmp/mongodb_user.js
  54. - service: mongodb_service
  55. - creates: {{ server.lock_dir }}/mongodb_password_changed
  56. {%- for database_name, database in server.get('database', {}).iteritems() %}
  57. /var/tmp/mongodb_user_{{ database_name }}.js:
  58. file.managed:
  59. - source: salt://mongodb/files/user_role.js
  60. - template: jinja
  61. - mode: 600
  62. - user: root
  63. - defaults:
  64. database_name: {{ database_name }}
  65. mongodb_{{ database_name }}_fix_role:
  66. cmd.run:
  67. - 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'
  68. {%- if grains.get('noservices') %}
  69. - onlyif: /bin/false
  70. {%- endif %}
  71. - require:
  72. - file: /var/tmp/mongodb_user_{{ database_name }}.js
  73. - service: mongodb_service
  74. - creates: {{ server.lock_dir }}/mongodb_user_{{ database_name }}_created
  75. {%- if server.members is defined %}
  76. require:
  77. - cmd: mongodb_setup_cluster
  78. {%- endif %}
  79. {%- endfor %}
  80. {%- if server.members is defined %}
  81. /var/tmp/mongodb_cluster.js:
  82. file.managed:
  83. - source: salt://mongodb/files/cluster.js
  84. - template: jinja
  85. - mode: 600
  86. - user: root
  87. mongodb_setup_cluster:
  88. cmd.run:
  89. - name: 'mongo localhost:27017/admin /var/tmp/mongodb_cluster.js && mongo localhost:27017/admin --quiet --eval "rs.conf()" | grep object -q'
  90. - unless: 'mongo localhost:27017/admin -u admin -p {{ server.admin.password }} --quiet --eval "rs.conf()" | grep object -q'
  91. - require:
  92. - service: mongodb_service
  93. - file: /var/tmp/mongodb_cluster.js
  94. - require_in:
  95. - cmd: mongodb_change_root_password
  96. {%- endif %}
  97. {%- endif %}
  98. {%- endif %}