Saltstack Official MongoDB Formula
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

9 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. mongodb_database_{{ database_name }}:
  52. mongodb_user.present:
  53. - name: {{ database_name }}
  54. - passwd: {{ database.password }}
  55. {%- if server.members is defined %}
  56. require:
  57. - cmd: mongodb_setup_cluster
  58. {%- endif %}
  59. /var/tmp/mongodb_user_{{ database_name }}.js:
  60. file.managed:
  61. - source: salt://mongodb/files/user_role.js
  62. - template: jinja
  63. - mode: 600
  64. - user: root
  65. - require:
  66. - mongodb_user: {{ database_name }}
  67. - defaults:
  68. database_name: {{ database_name }}
  69. mongodb_{{ database_name }}_fix_role:
  70. cmd.run:
  71. - 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'
  72. - require:
  73. - file: /var/tmp/mongodb_user_{{ database_name }}.js
  74. - service: mongodb_service
  75. - creates: {{ server.lock_dir }}/mongodb_user_{{ database_name }}_created
  76. {%- endfor %}
  77. {%- if server.members is defined %}
  78. /var/tmp/mongodb_cluster.js:
  79. file.managed:
  80. - source: salt://mongodb/files/cluster.js
  81. - template: jinja
  82. - mode: 600
  83. - user: root
  84. mongodb_setup_cluster:
  85. cmd.run:
  86. - name: 'mongo localhost:27017/admin /var/tmp/mongodb_cluster.js && mongo localhost:27017/admin --quiet --eval "rs.conf()" | grep object -q'
  87. - unless: 'mongo localhost:27017/admin -u admin -p {{ server.admin.password }} --quiet --eval "rs.conf()" | grep object -q'
  88. - require:
  89. - service: mongodb_service
  90. - file: /var/tmp/mongodb_cluster.js
  91. - require_in:
  92. - cmd: mongodb_change_root_password
  93. {%- endif %}
  94. {%- endif %}
  95. {%- endif %}