Saltstack Official MongoDB Formula
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

126 lines
3.3KB

  1. {%- from "mongodb/map.jinja" import server with context %}
  2. {%- if server.get('enabled', False) %}
  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 defined and server.master == pillar.linux.system.name %}
  39. /var/tmp/mongodb_cluster.js:
  40. file.managed:
  41. - source: salt://mongodb/files/cluster.js
  42. - template: jinja
  43. - mode: 600
  44. - user: root
  45. mongodb_setup_cluster_wait:
  46. cmd.run:
  47. - name: 'sleep 10'
  48. - unless: 'mongo localhost:27017 --quiet --eval "rs.conf()" | grep -i object -q'
  49. - require:
  50. - service: mongodb_service
  51. - file: /var/tmp/mongodb_cluster.js
  52. mongodb_setup_cluster:
  53. cmd.run:
  54. - name: 'mongo localhost:27017 /var/tmp/mongodb_cluster.js && mongo localhost:27017 --quiet --eval "rs.conf()" | grep -i object -q'
  55. - unless: 'mongo localhost:27017 --quiet --eval "rs.conf()" | grep -i object -q'
  56. - require:
  57. - service: mongodb_service
  58. - file: /var/tmp/mongodb_cluster.js
  59. - cmd: mongodb_setup_cluster_wait
  60. {%- endif %}
  61. {%- if server.members is not defined or server.master == pillar.linux.system.name %}
  62. {%- if server.authorization.get('enabled', False) %}
  63. /var/tmp/mongodb_user.js:
  64. file.managed:
  65. - source: salt://mongodb/files/user.js
  66. - template: jinja
  67. - mode: 600
  68. - user: root
  69. mongodb_change_root_password:
  70. cmd.run:
  71. - name: 'mongo localhost:27017/admin /var/tmp/mongodb_user.js && touch {{ server.lock_dir }}/mongodb_password_changed'
  72. {%- if grains.get('noservices') %}
  73. - onlyif: /bin/false
  74. {%- endif %}
  75. - require:
  76. - file: /var/tmp/mongodb_user.js
  77. - service: mongodb_service
  78. - creates: {{ server.lock_dir }}/mongodb_password_changed
  79. {%- for database_name, database in server.get('database', {}).iteritems() %}
  80. /var/tmp/mongodb_user_{{ database_name }}.js:
  81. file.managed:
  82. - source: salt://mongodb/files/user_role.js
  83. - template: jinja
  84. - mode: 600
  85. - user: root
  86. - defaults:
  87. database_name: {{ database_name }}
  88. mongodb_{{ database_name }}_fix_role:
  89. cmd.run:
  90. - 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'
  91. {%- if grains.get('noservices') %}
  92. - onlyif: /bin/false
  93. {%- endif %}
  94. - require:
  95. - file: /var/tmp/mongodb_user_{{ database_name }}.js
  96. - service: mongodb_service
  97. - creates: {{ server.lock_dir }}/mongodb_user_{{ database_name }}_created
  98. {%- if server.members is defined %}
  99. require:
  100. - cmd: mongodb_setup_cluster
  101. {%- endif %}
  102. {%- endfor %}
  103. {%- endif %}
  104. {%- endif %}
  105. {%- endif %}