main.yml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ---
  2. - name: Install graphite
  3. apt:
  4. pkg: "{{ item }}"
  5. update_cache: yes
  6. state: installed
  7. with_items:
  8. - graphite-web
  9. - graphite-carbon
  10. - uwsgi
  11. - uwsgi-plugin-python
  12. - name: Deploy local_settings.py
  13. template: src=local_settings.py.j2 dest=/etc/graphite/local_settings.py
  14. notify:
  15. - restart uwsgi
  16. - name: Start carbon-cache on startup
  17. lineinfile:
  18. dest: "/etc/default/graphite-carbon"
  19. regexp: '^CARBON_CACHE_ENABLED='
  20. line: 'CARBON_CACHE_ENABLED=true'
  21. - name: Deploy carbon.conf
  22. template: src=carbon.conf.j2 dest=/etc/carbon/carbon.conf
  23. notify:
  24. - restart carbon-cache-instances
  25. - restart carbon-relay
  26. - name: Deploy storage-schemas.conf
  27. template: src=storage-schemas.conf.j2 dest=/etc/carbon/storage-schemas.conf
  28. notify:
  29. - restart carbon-cache-instances
  30. - name: Deploy graphite.ini
  31. template: src=graphite.ini dest=/etc/uwsgi/apps-available/graphite.ini
  32. notify:
  33. - restart uwsgi
  34. - name: Enable graphite.ini
  35. file:
  36. src: /etc/uwsgi/apps-available/graphite.ini
  37. dest: /etc/uwsgi/apps-enabled/graphite.ini
  38. state: link
  39. notify:
  40. - restart uwsgi
  41. - name: Create database for graphite-web
  42. shell: "graphite-manage syncdb --noinput"
  43. args:
  44. creates: "/var/lib/graphite/graphite.db"
  45. - name: Ensure directories are owned by www-data
  46. file: path="{{item}}" state=directory owner=www-data group=www-data recurse=yes
  47. with_items:
  48. - "/usr/share/graphite-web"
  49. - "/var/log/graphite"
  50. - "/var/lib/graphite"
  51. - name: Deploy carbon-cache@.service template file
  52. copy: src=carbon-cache@.service dest=/lib/systemd/system/carbon-cache@.service
  53. register: _cc_systemd
  54. notify:
  55. - restart carbon-cache-instances
  56. - name: Deploy carbon-relay.service template file
  57. copy: src=carbon-relay.service dest=/lib/systemd/system/carbon-relay.service
  58. register: _cr_systemd
  59. notify:
  60. - restart carbon-relay
  61. - name: reload systemd
  62. shell: systemctl daemon-reload
  63. when: _cc_systemd.changed or _cr_systemd.changed
  64. - name: Stop and disable default carbon-cache systemd script
  65. service: name="carbon-cache.service" state=stopped enabled=no
  66. - name: Enable carbon-cache instances
  67. service: name="carbon-cache@{{item.name}}.service" enabled=yes
  68. with_items:
  69. - "{{graphite.cache_instances}}"
  70. - name: Get all enabled carbon-cache instances
  71. shell: '/bin/ls /etc/systemd/system/multi-user.target.wants/carbon-cache@* | /bin/grep -oE "carbon-cache@[^\.]+" | /bin/sed "s/carbon-cache@//g"'
  72. changed_when: False
  73. failed_when: False
  74. check_mode: no
  75. register: _cc_instances
  76. - name: Generate list with names of defined carbon-cache instances
  77. set_fact:
  78. _cc_should_instances: "{{ graphite.cache_instances | map(attribute='name') | list}}"
  79. - name: Stop and disable obsolete cc instances
  80. service: name="carbon-cache@{{item}}.service" enabled=no state=stopped
  81. with_items: "{{_cc_instances.stdout_lines}}"
  82. when: item not in _cc_should_instances
  83. notify:
  84. - restart carbon-relay
  85. - name: Enable services
  86. service: name="{{item}}" enabled=yes
  87. with_items:
  88. - "carbon-relay.service"
  89. - "uwsgi.service"