init.sls 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #
  2. # mongodb
  3. #
  4. mongodb-repo:
  5. pkgrepo.managed:
  6. - humanname: MongoDB Repo
  7. - file: /etc/apt/sources.list.d/mongodb-org.list
  8. - key_url: https://www.mongodb.org/static/pgp/server-{{ mongodb_version }}.asc
  9. {% if mongodb_version == '4.2' %}
  10. - name: deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.2 main
  11. {% elif mongodb_version == '4.4' %}
  12. - name: deb http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4 main
  13. {% elif mongodb_version == '5.0' %}
  14. - name: deb http://repo.mongodb.org/apt/debian {{ grains.oscodename }}/mongodb-org/5.0 main
  15. {% endif %}
  16. mongodb:
  17. pkg.installed:
  18. - pkgs:
  19. - mongodb-org
  20. - python3-pymongo
  21. service.running:
  22. - name: mongod
  23. - enable: True
  24. - require:
  25. - pkg: mongodb
  26. - watch:
  27. - file: /etc/mongod.conf
  28. # Create mongodb admin user
  29. mongoadmin:
  30. mongodb_user.present:
  31. - name: {{ mongodb_admin_username }}
  32. - passwd: {{ mongodb_admin_password }}
  33. - database: admin
  34. - roles: {{ mongodb_admin_roles }}
  35. - user: {{ mongodb_admin_username }}
  36. - password: {{ mongodb_admin_password }}
  37. # Install mongod config, cronjob, backup script and corresponding config file
  38. /etc/mongod.conf:
  39. file.managed:
  40. - source: salt://mongodb/mongod.conf
  41. - require:
  42. - mongodb_user: mongoadmin
  43. /etc/cron.d/mongodb_backup:
  44. file.managed:
  45. - source: salt://mongodb/mongodb_backup.cron
  46. /usr/local/sbin/mongodb_backup:
  47. file.managed:
  48. - source: salt://mongodb/mongodb_backup
  49. - mode: 755
  50. /etc/mongodb_backup.conf:
  51. file.managed:
  52. - source: salt://mongodb/mongodb_backup.conf
  53. - mode: 600
  54. - user: root
  55. - group: root