Saltstack Official MongoDB Formula
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

110 linhas
2.8KB

  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. - require:
  31. - file: {{ server.lock_dir }}
  32. - pkg: mongodb_packages
  33. - watch:
  34. - file: /etc/mongodb.conf
  35. {%- if server.members is not defined or server.master == pillar.linux.system.name %}
  36. {# We are not a cluster or we are master #}
  37. /var/tmp/mongodb_user.js:
  38. file.managed:
  39. - source: salt://mongodb/files/user.js
  40. - template: jinja
  41. - mode: 600
  42. - user: root
  43. mongodb_change_root_password:
  44. cmd.run:
  45. - name: 'mongo localhost:27017/admin /var/tmp/mongodb_user.js && touch {{ server.lock_dir }}/mongodb_password_changed'
  46. - require:
  47. - file: /var/tmp/mongodb_user.js
  48. - service: mongodb_service
  49. - creates: {{ server.lock_dir }}/mongodb_password_changed
  50. {%- for database_name, database in server.get('database', {}).iteritems() %}
  51. /var/tmp/mongodb_user_{{ database_name }}.js:
  52. file.managed:
  53. - source: salt://mongodb/files/user_role.js
  54. - template: jinja
  55. - mode: 600
  56. - user: root
  57. - defaults:
  58. database_name: {{ database_name }}
  59. mongodb_{{ database_name }}_fix_role:
  60. cmd.run:
  61. - 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'
  62. - require:
  63. - file: /var/tmp/mongodb_user_{{ database_name }}.js
  64. - service: mongodb_service
  65. - creates: {{ server.lock_dir }}/mongodb_user_{{ database_name }}_created
  66. {%- if server.members is defined %}
  67. require:
  68. - cmd: mongodb_setup_cluster
  69. {%- endif %}
  70. {%- endfor %}
  71. {%- if server.members is defined %}
  72. /var/tmp/mongodb_cluster.js:
  73. file.managed:
  74. - source: salt://mongodb/files/cluster.js
  75. - template: jinja
  76. - mode: 600
  77. - user: root
  78. mongodb_setup_cluster:
  79. cmd.run:
  80. - name: 'mongo localhost:27017/admin /var/tmp/mongodb_cluster.js && mongo localhost:27017/admin --quiet --eval "rs.conf()" | grep object -q'
  81. - unless: 'mongo localhost:27017/admin -u admin -p {{ server.admin.password }} --quiet --eval "rs.conf()" | grep object -q'
  82. - require:
  83. - service: mongodb_service
  84. - file: /var/tmp/mongodb_cluster.js
  85. - require_in:
  86. - cmd: mongodb_change_root_password
  87. {%- endif %}
  88. {%- endif %}
  89. {%- endif %}