Procházet zdrojové kódy

Docs for client_templates and adding run_once to local tasks

- added run_once: true to local tasks for better performance
- added docs for client_templates
- updated changelog.
Michael Porter před 6 roky
rodič
revize
934b45a912
5 změnil soubory, kde provedl 87 přidání a 19 odebrání
  1. 2 0
      CHANGELOG.md
  2. 61 7
      docs/dynamic_checks.md
  3. 14 5
      docs/index.md
  4. 6 7
      molecule/shared/tests/test_default.rb
  5. 4 0
      tasks/plugins.yml

+ 2 - 0
CHANGELOG.md

@@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/)
 The format is based on [Keep a Changelog](http://keepachangelog.com/).
 
 ## [Unreleased]
+- Add `client_templates` option for group based tempaltes (@michaelpporter)
+- Add `run_once: true` to `delegate_to: localhost` (@michaelpporter)
 
 ## [5.0.0] - 2019-02-19
 ### Breaking Changes

+ 61 - 7
docs/dynamic_checks.md

@@ -15,12 +15,14 @@ data/static
     |-- handlers
     `-- mutators
 ```
-With all the checks and definitions dropped in, the static data store might look something like this:
+With all the checks (check commands) and definitions (JSON check files) dropped in, the static data store might look something like this:
 ```
 $ tree data/static
 data/static
 `-- sensu
     |-- checks
+    |   |-- mysql
+    |   |   `-- check_mysql.sh
     |   |-- sensu_rabbitmq_servers
     |   |   `-- check_rabbitmq.sh
     |   |-- sensu_redis_servers
@@ -42,6 +44,11 @@ data/static
     |   `-- smartos_check_mem.json.j2
     |-- client_definitions
     |   |-- sensu_rabbitmq_servers
+    |   |   `-- check_users.json
+    |   `-- webservers
+    |       `-- check_uptime.json
+    |-- client_templates
+    |   |-- mysql
     |   |   `-- check_users.json.j2
     |   `-- webservers
     |       `-- check_uptime.json.j2
@@ -49,7 +56,7 @@ data/static
     |   `-- pushover.rb
     `-- mutators
 ```
-As you can see, in the `sensu/checks` directory, there are the `sensu_rabbitmq_servers`, `sensu_redis_servers`, `webservers` & `zones` subdirectories.
+As you can see, in the `sensu/checks` directory, there are the `mysql`, `sensu_rabbitmq_servers`, `sensu_redis_servers`, `webservers` & `zones` subdirectories.
 If you've had a peruse through some of the other documentation here, you'll know that these groups are defined within my Ansible inventory:
 ``` ini
 [sensu_rabbitmq_servers]
@@ -69,6 +76,9 @@ tater.cmacr.ae
 beardy.cmacr.ae
 pkgsrc.cmacr.ae
 
+[mysql]
+mysql.cmacr.ae
+
 [zones]
 ansible.cmacr.ae
 beardy.cmacr.ae
@@ -83,6 +93,7 @@ sensu.cmacr.ae
 tater.cmacr.ae
 web.cmacr.ae
 test.cmacr.ae
+mysql.cmacr.ae
 ```
 Under these subdirectories, you can see [checks](https://docs.sensu.io/sensu-core/latest/reference/checks/) that relate to the directory they're placed in.
 For example, our `webservers` subdirectory includes a `check_nginx.sh` script, whilst the `sensu_rabbitmq_servers` subdirectory has one that most likely checks for RabbitMQ problems (it does... trust me).
@@ -110,26 +121,69 @@ This will [register](https://docs.ansible.com/ansible/latest/user_guide/playbook
 
 And, because nodes can of course be members of more than just one group, checks will be deployed in full to nodes that belong to several groups!
 
-Additionally, standalone checks can be distributed to hosts based on group membership. These definitions are located in the client_definitions folder. These will be deployed to the configuration directory of the clients.
+Additionally, standalone checks and subscription cheecks (if your client is in [safe_mode](https://docs.sensu.io/sensu-core/latest/reference/clients/)), can be distributed to hosts based on group membership. These definitions are located in the `client_definitions` folder. These will be deployed to the configuration directory of the clients.
 
 These are deployed with the following pair of plays, also in the `tasks/plugins.yml` playbook:
 ``` yaml
 - name: Register available client definitions
-  local_action: command ls {{ static_data_store }}/sensu/client_definitions
+  command: "ls {{ static_data_store }}/sensu/client_definitions"
+  delegate_to: localhost
   register: sensu_available_client_definitions
   changed_when: false
   become: false
+  run_once: true
 
 - name: Deploy client definitions
   copy:
     src: "{{ static_data_store }}/sensu/client_definitions/{{ item }}/"
-    dest: "{{ sensu_config_path }}/conf.d/{{ item | basename | regex_replace('.j2', '')}}"
-    mode: 0755
+    dest: "{{ sensu_config_path }}/conf.d/{{ item | basename | regex_replace('.j2', '') }}"
+    owner: "{{ sensu_user_name }}"
+    group: "{{ sensu_group_name }}"
+  when:
+    - sensu_available_client_definitions is defined
+    - sensu_available_client_definitions is not skipped
+    - item in sensu_available_client_definitions.stdout_lines
+  loop: "{{ group_names|flatten }}"
+  notify: restart sensu-client service
+```
+
+If you are using templates for your, standalone checks and subscription cheecks can be distributed from the  `client_templates` folder. These will be deployed to the configuration directory of the clients. **Note** if you have a matching folder/file name in the `client_definitions` they will be overwritten by the template.
+
+These are deployed with the following set of plays, also in the `tasks/plugins.yml` playbook:
+
+``` yaml
+- name: Register available client templates
+  command: "ls {{ static_data_store }}/sensu/client_templates"
+  delegate_to: localhost
+  register: sensu_available_client_templates
+  changed_when: false
+  become: false
+  run_once: true
+
+- name: Deploy client template folders
+  file:
+    path: '{{ sensu_config_path }}/conf.d/{{ item | basename }}'
+    state: directory
     owner: "{{ sensu_user_name }}"
     group: "{{ sensu_group_name }}"
-  when: "sensu_available_client_definitions is defined and item in sensu_available_client_definitions.stdout_lines"
+  when:
+    - sensu_available_client_templates is defined
+    - sensu_available_client_templates is not skipped
+    - item in sensu_available_client_templates.stdout_lines
   loop: "{{ group_names|flatten }}"
   notify: restart sensu-client service
+
+- name: Deploy client templates
+  template:
+    src: "{{ static_data_store }}/sensu/client_templates/{{ item.path | dirname }}/{{ item.path | basename }}"
+    dest: "{{ sensu_config_path }}/conf.d/{{ item.path | dirname }}/{{ item.path | basename | regex_replace('.j2', '') }}"
+    owner: "{{ sensu_user_name }}"
+    group: "{{ sensu_group_name }}"
+  with_filetree: "{{ static_data_store }}/sensu/client_templates"
+  when:
+    - item.state == 'file'
+    - item.path | dirname in group_names
+  notify: restart sensu-client service
 ```
 
 ## Picking up changes on the fly

+ 14 - 5
docs/index.md

@@ -1,7 +1,9 @@
 # Ansible Sensu [![Ansible Galaxy](https://img.shields.io/badge/galaxy-sensu.sensu-660198.svg?style=flat)](https://galaxy.ansible.com/sensu/sensu/)
+
 An [Ansible](https://ansible.com) role that deploys a full [Sensu](https://sensuapp.org) stack, a modern, open source monitoring framework.
 
 ## Features
+
 - Deploy a full [Sensu](https://sensu.io) stack, including RabbitMQ, redis, and the [Uchiwa dashboard](https://uchiwa.io/)
 - Tight integration with the Ansible inventory - deployment of monitoring checks based on inventory grouping
 - Fine grained control over dynamic client configurations
@@ -14,9 +16,11 @@ Along with deploying the Sensu Server, API and clients, this role can deploy a f
 However, if you want to rely on other roles/management methods to deploy/manage these services, [it's nice and easy to integrate this role](integration/).
 
 ## Requirements
+
 This role requires Ansible 2.5
 
 ## Supported Platforms
+
 ### Automatically tested via TravisCI
 
 - [CentOS - 6](https://wiki.centos.org/Manuals/ReleaseNotes/CentOS6.9)
@@ -32,15 +36,18 @@ This role requires Ansible 2.5
 - [Amazon Linux 2](https://aws.amazon.com/amazon-linux-2/)
 
 ### Supported manually (compatibility not always guaranteed)
+
 - [SmartOS - base-64 15.x.x](https://docs.joyent.com/images/smartos/base#version-15xx)
 - [FreeBSD - 10.3, 11.0 (64-bit only)](https://www.freebsd.org/releases/10.2R/relnotes.html)
 - [OpenBSD - 6.2](https://www.openbsd.org/62.html)
 
 ## Role Variables
+
 All variables have sensible defaults, which can be found in `defaults/main.yml`.
 Head over to [the role variables page](role_variables.md) to review them
 
 ## Install (Ansible Galaxy)
+
 To install this role from [Ansible Galaxy](https://galaxy.ansible.com), simpy run:
 `ansible-galaxy install sensu.sensu`
 
@@ -51,6 +58,7 @@ To install this role from [Ansible Galaxy](https://galaxy.ansible.com), simpy ru
     roles:
       - role: sensu.sensu
 ```
+
 Or, passing parameter values:
 
 ``` yaml
@@ -58,19 +66,20 @@ Or, passing parameter values:
     roles:
       - role: sensu.sensu
         sensu_master: true
-        sensu_include_dashboard: true 
+        sensu_include_dashboard: true
 ```
 
-License
--------
+## License
+
 [MIT](license.md)
 
-Author Information
-------------------
+## Author Information
+
 Originally created by [Calum MacRae](http://cmacr.ae)
 Supported by the [Sensu Community Ansible Maintainers](https://github.com/sensu-plugins/community/#maintained-areas)
 
 ### Contributors
+
 See the projects [Contributors page](https://github.com/sensu/sensu-ansible/graphs/contributors)
 
 Feel free to:

+ 6 - 7
molecule/shared/tests/test_default.rb

@@ -52,16 +52,15 @@ describe http('http://127.0.0.1:4567/health',
 end
 
 # Ensure disk check exists
-describe file('/etc/sensu/conf.d/sensu_masters/check_disk_usage.json') do
-  it { should exist }
-  its('content') { should match(/check-disk-usage/) }
+describe json('/etc/sensu/conf.d/sensu_masters/check_disk_usage.json') do
+  its(['checks','metrics_disk_usage','command') { should eq 'check-disk-usage.rb' }
+  its(['checks','metrics_disk_usage','interval']) { should eq 120 }
 end
 
 # Ensure disk metrics exists
-describe file('/etc/sensu/conf.d/sensu_checks/metrics_disk_usage.json') do
-  it { should exist }
-  its('content') { should match(/metrics-disk-usage/) }
-  its('content') { should match(/60/) }
+describe json('/etc/sensu/conf.d/sensu_checks/metrics_disk_usage.json') do
+  its(['checks','metrics_disk_usage','command') { should eq 'metrics-disk-usage.rb' }
+  its(['checks','metrics_disk_usage','interval']) { should eq 60 }
 end
 
 # Ensure not_used does not exist

+ 4 - 0
tasks/plugins.yml

@@ -18,6 +18,7 @@
     dest: "{{ static_data_store }}/sensu/{{ item }}"
   delegate_to: localhost
   become: no
+  run_once: true
   loop:
     - checks
     - filters
@@ -39,6 +40,7 @@
   register: sensu_available_checks
   changed_when: false
   become: false
+  run_once: true
 
 - name: Deploy check plugins
   copy:
@@ -101,6 +103,7 @@
   register: sensu_available_client_definitions
   changed_when: false
   become: false
+  run_once: true
 
 - name: Deploy client definitions
   copy:
@@ -121,6 +124,7 @@
   register: sensu_available_client_templates
   changed_when: false
   become: false
+  run_once: true
 
 - name: Deploy client template folders
   file: