plugins.yml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. ---
  2. # tasks/plugins.yml: Deploy available checks/plugins/handlers/filters/mutators
  3. - name: Include ansible_distribution vars
  4. include_vars:
  5. file: "{{ ansible_distribution }}.yml"
  6. - name: Ensure Sensu plugin directory exists
  7. file:
  8. dest: "{{ sensu_config_path }}/plugins"
  9. state: directory
  10. owner: "{{ sensu_user_name }}"
  11. group: "{{ sensu_group_name }}"
  12. - name: Ensure local directories exist
  13. file:
  14. state: directory
  15. dest: "{{ static_data_store }}/sensu/{{ item }}"
  16. delegate_to: localhost
  17. become: no
  18. loop:
  19. - checks
  20. - filters
  21. - handlers
  22. - mutators
  23. - definitions
  24. - client_definitions
  25. - client_templates
  26. - name: Ensure any remote plugins defined are present
  27. shell: umask 0022; sensu-install -p {{ item }}
  28. loop: "{{ sensu_remote_plugins }}"
  29. changed_when: false
  30. when: sensu_remote_plugins | length > 0
  31. - name: Register available checks
  32. command: "ls {{ static_data_store }}/sensu/checks"
  33. delegate_to: localhost
  34. register: sensu_available_checks
  35. changed_when: false
  36. become: false
  37. - name: Deploy check plugins
  38. copy:
  39. src: "{{ static_data_store }}/sensu/checks/{{ item }}/"
  40. dest: "{{ sensu_config_path }}/plugins/"
  41. mode: 0755
  42. owner: "{{ sensu_user_name }}"
  43. group: "{{ sensu_group_name }}"
  44. when:
  45. - sensu_available_checks is defined
  46. - sensu_available_checks is not skipped
  47. - item in sensu_available_checks.stdout_lines
  48. loop: "{{ group_names|flatten }}"
  49. notify: restart sensu-client service
  50. - name: Deploy handler plugins
  51. copy:
  52. src: "{{ static_data_store }}/sensu/handlers/"
  53. dest: "{{ sensu_config_path }}/plugins/"
  54. mode: 0755
  55. owner: "{{ sensu_user_name }}"
  56. group: "{{ sensu_group_name }}"
  57. notify: restart sensu-client service
  58. - name: Deploy filter plugins
  59. copy:
  60. src: "{{ static_data_store }}/sensu/filters/"
  61. dest: "{{ sensu_config_path }}/plugins/"
  62. mode: 0755
  63. owner: "{{ sensu_user_name }}"
  64. group: "{{ sensu_group_name }}"
  65. notify: restart sensu-client service
  66. - name: Deploy mutator plugins
  67. copy:
  68. src: "{{ static_data_store }}/sensu/mutators/"
  69. dest: "{{ sensu_config_path }}/plugins/"
  70. mode: 0755
  71. owner: "{{ sensu_user_name }}"
  72. group: "{{ sensu_group_name }}"
  73. notify: restart sensu-client service
  74. - name: Deploy check/handler/filter/mutator definitions to the master
  75. template:
  76. src: "{{ item }}"
  77. dest: "{{ sensu_config_path }}/conf.d/{{ item | basename | regex_replace('.j2', '') }}"
  78. owner: "{{ sensu_user_name }}"
  79. group: "{{ sensu_group_name }}"
  80. when: sensu_master
  81. with_fileglob:
  82. - "{{ static_data_store }}/sensu/definitions/*"
  83. notify:
  84. - restart sensu-server service
  85. - restart sensu-api service
  86. - restart sensu-enterprise service
  87. - name: Register available client definitions
  88. command: "ls {{ static_data_store }}/sensu/client_definitions"
  89. delegate_to: localhost
  90. register: sensu_available_client_definitions
  91. changed_when: false
  92. become: false
  93. - name: Deploy client definitions
  94. copy:
  95. src: "{{ static_data_store }}/sensu/client_definitions/{{ item }}/"
  96. dest: "{{ sensu_config_path }}/conf.d/{{ item | basename | regex_replace('.j2', '') }}"
  97. owner: "{{ sensu_user_name }}"
  98. group: "{{ sensu_group_name }}"
  99. when:
  100. - sensu_available_client_definitions is defined
  101. - sensu_available_client_definitions is not skipped
  102. - item in sensu_available_client_definitions.stdout_lines
  103. loop: "{{ group_names|flatten }}"
  104. notify: restart sensu-client service
  105. - name: Register available client templates
  106. command: "ls {{ static_data_store }}/sensu/client_templates"
  107. delegate_to: localhost
  108. register: sensu_available_client_templates
  109. changed_when: false
  110. become: false
  111. - name: Deploy client template folders
  112. file:
  113. path: '{{ sensu_config_path }}/conf.d/{{ item | basename }}'
  114. state: directory
  115. owner: "{{ sensu_user_name }}"
  116. group: "{{ sensu_group_name }}"
  117. when:
  118. - sensu_available_client_templates is defined
  119. - sensu_available_client_templates is not skipped
  120. - item in sensu_available_client_templates.stdout_lines
  121. loop: "{{ group_names|flatten }}"
  122. notify: restart sensu-client service
  123. - name: Deploy client templates
  124. template:
  125. src: "{{ static_data_store }}/sensu/client_templates/{{ item.path | dirname }}/{{ item.path | basename }}"
  126. dest: "{{ sensu_config_path }}/conf.d/{{ item.path | dirname }}/{{ item.path | basename | regex_replace('.j2', '') }}"
  127. owner: "{{ sensu_user_name }}"
  128. group: "{{ sensu_group_name }}"
  129. with_filetree: "{{ static_data_store }}/sensu/client_templates"
  130. when:
  131. - item.state == 'file'
  132. - item.path | dirname in group_names
  133. notify: restart sensu-client service