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.

server.sls 3.2KB

il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
il y a 9 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. {%- if not grains.get('noservices', False) %}
  21. - watch_in:
  22. - service: mongodb_service
  23. {%- endif %}
  24. {%- endif %}
  25. {{ server.lock_dir }}:
  26. file.directory:
  27. - makedirs: true
  28. {%- if not grains.get('noservices', False) %}
  29. mongodb_service:
  30. service.running:
  31. - name: {{ server.service }}
  32. - enable: true
  33. - require:
  34. - file: {{ server.lock_dir }}
  35. - pkg: mongodb_packages
  36. - watch:
  37. - file: /etc/mongodb.conf
  38. {%- endif %}
  39. {%- if server.members is not defined or server.master == pillar.linux.system.name %}
  40. {# We are not a cluster or we are master #}
  41. /var/tmp/mongodb_user.js:
  42. file.managed:
  43. - source: salt://mongodb/files/user.js
  44. - template: jinja
  45. - mode: 600
  46. - user: root
  47. {%- if not grains.get('noservices', False) %}
  48. mongodb_change_root_password:
  49. cmd.run:
  50. - name: 'mongo localhost:27017/admin /var/tmp/mongodb_user.js && touch {{ server.lock_dir }}/mongodb_password_changed'
  51. - require:
  52. - file: /var/tmp/mongodb_user.js
  53. - service: mongodb_service
  54. - creates: {{ server.lock_dir }}/mongodb_password_changed
  55. {%- endif %}
  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. {%- if not grains.get('noservices', False) %}
  66. mongodb_{{ database_name }}_fix_role:
  67. cmd.run:
  68. - 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'
  69. - require:
  70. - file: /var/tmp/mongodb_user_{{ database_name }}.js
  71. {%- if not grains.get('noservices', False) %}
  72. - service: mongodb_service
  73. {%- endif%}
  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. {%- endif %}
  80. {%- endfor %}
  81. {%- if server.members is defined %}
  82. /var/tmp/mongodb_cluster.js:
  83. file.managed:
  84. - source: salt://mongodb/files/cluster.js
  85. - template: jinja
  86. - mode: 600
  87. - user: root
  88. mongodb_setup_cluster:
  89. cmd.run:
  90. - name: 'mongo localhost:27017/admin /var/tmp/mongodb_cluster.js && mongo localhost:27017/admin --quiet --eval "rs.conf()" | grep object -q'
  91. - unless: 'mongo localhost:27017/admin -u admin -p {{ server.admin.password }} --quiet --eval "rs.conf()" | grep object -q'
  92. - require:
  93. {%- if not grains.get('noservices', False) %}
  94. - service: mongodb_service
  95. {%- endif %}
  96. - file: /var/tmp/mongodb_cluster.js
  97. - require_in:
  98. - cmd: mongodb_change_root_password
  99. {%- endif %}
  100. {%- endif %}
  101. {%- endif %}