plugins.yml 4.7 KB

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