Optimize reconfigure action for telegraf
Change-Id: Ia658b0774ce009feb6b4e73363114f7922833835 Partially-implements: blueprint better-reconfigure
This commit is contained in:
parent
7ed9cb246f
commit
b4632d2a24
@ -1,6 +1,22 @@
|
||||
---
|
||||
project_name: "telegraf"
|
||||
|
||||
telegraf_services:
|
||||
telegraf:
|
||||
container_name: "telegraf"
|
||||
image: "{{ telegraf_image_full }}"
|
||||
enabled: true
|
||||
pid_mode: "host"
|
||||
group: "telegraf"
|
||||
volumes:
|
||||
- "{{ node_config_directory }}/telegraf/:{{ container_config_directory }}/:ro"
|
||||
- "/etc/localtime:/etc/localtime:ro"
|
||||
- "kolla_logs:/var/log/kolla/"
|
||||
- "/sys:/rootfs/sys:ro"
|
||||
- "/proc:/rootfs/proc:ro"
|
||||
- "/var/run/docker.sock:/var/run/docker.sock:ro"
|
||||
|
||||
|
||||
####################
|
||||
# Docker
|
||||
####################
|
||||
|
25
ansible/roles/telegraf/handlers/main.yml
Normal file
25
ansible/roles/telegraf/handlers/main.yml
Normal file
@ -0,0 +1,25 @@
|
||||
---
|
||||
- name: Restart telegraf container
|
||||
vars:
|
||||
service_name: "telegraf"
|
||||
service: "{{ telegraf_services[service_name] }}"
|
||||
config_json: "{{ telegraf_config_jsons.results|selectattr('item.key', 'equalto', service_name)|first }}"
|
||||
telegraf_container: "{{ check_telegraf_containers.results|selectattr('item.key', 'equalto', service_name)|first }}"
|
||||
kolla_docker:
|
||||
action: "recreate_or_restart_container"
|
||||
common_options: "{{ docker_common_options }}"
|
||||
name: "{{ service.container_name }}"
|
||||
pid_mode: "{{ service.pid_mode }}"
|
||||
environment:
|
||||
HOST_PROC: "/rootfs/proc"
|
||||
HOST_SYS: "/rootfs/sys"
|
||||
image: "{{ service.image }}"
|
||||
volumes: "{{ service.volumes|reject('equalto', '')|list }}"
|
||||
when:
|
||||
- action != "config"
|
||||
- inventory_hostname in groups[service.group]
|
||||
- service.enabled | bool
|
||||
- config_json.changed | bool
|
||||
or telegraf_confs.changed | bool
|
||||
or telegraf_plugin.changed | bool
|
||||
or telegraf_container.changed | bool
|
@ -1,26 +1,68 @@
|
||||
---
|
||||
- name: Ensuring config directories exist
|
||||
file:
|
||||
path: "{{ node_config_directory }}/{{ item }}"
|
||||
path: "{{ node_config_directory }}/{{ item.key }}/config"
|
||||
state: "directory"
|
||||
recurse: yes
|
||||
with_items:
|
||||
- "telegraf"
|
||||
- "telegraf/config"
|
||||
when:
|
||||
- inventory_hostname in groups[item.value.group]
|
||||
- item.value.enabled | bool
|
||||
with_dict: "{{ telegraf_services }}"
|
||||
|
||||
- name: Copying over default config.json files
|
||||
vars:
|
||||
service: "{{ telegraf_services['telegraf_services'] }}"
|
||||
template:
|
||||
src: "telegraf.json.j2"
|
||||
dest: "{{ node_config_directory }}/telegraf/config.json"
|
||||
register: telegraf_config_jsons
|
||||
when:
|
||||
- inventory_hostname in groups[item.value.group]
|
||||
- item.value.enabled | bool
|
||||
with_dict: "{{ telegraf_services }}"
|
||||
notify:
|
||||
- Restart telegraf container
|
||||
|
||||
- name: Copying over telegraf config file
|
||||
vars:
|
||||
service: "{{ telegraf_services['telegraf'] }}"
|
||||
template:
|
||||
src: "telegraf.conf.j2"
|
||||
dest: "{{ node_config_directory }}/telegraf/telegraf.conf"
|
||||
register: telegraf_confs
|
||||
when:
|
||||
- inventory_hostname in groups[service.group]
|
||||
- service.enabled | bool
|
||||
notify:
|
||||
- Restart telegraf container
|
||||
|
||||
- name: Copying over telegraf plugin files
|
||||
vars:
|
||||
service: "{{ telegraf_services['telegraf'] }}"
|
||||
copy:
|
||||
src: "{{ item }}"
|
||||
dest: "{{ node_config_directory }}/telegraf/config"
|
||||
register: telegraf_plugin
|
||||
when:
|
||||
- inventory_hostname in groups[service.group]
|
||||
- item.value.enabled | bool
|
||||
with_fileglob:
|
||||
- "{{ role_path }}/templates/config/*.conf"
|
||||
notify:
|
||||
- Restart telegraf container
|
||||
|
||||
- name: Check telegraf containers
|
||||
kolla_docker:
|
||||
action: "compare_container"
|
||||
common_options: "{{ docker_common_options }}"
|
||||
name: "{{ item.value.container_name }}"
|
||||
image: "{{ item.value.image }}"
|
||||
volumes: "{{ item.value.volumes }}"
|
||||
register: check_telegraf_containers
|
||||
when:
|
||||
- action != "config"
|
||||
- inventory_hostname in groups[item.value.group]
|
||||
- item.value.enabled | bool
|
||||
with_dict: "{{ telegraf_services }}"
|
||||
notify:
|
||||
- Restart telegraf container
|
||||
|
@ -1,4 +1,5 @@
|
||||
---
|
||||
- include: config.yml
|
||||
|
||||
- include: start.yml
|
||||
- name: Flush handlers
|
||||
meta: flush_handlers
|
||||
|
@ -3,4 +3,8 @@
|
||||
kolla_docker:
|
||||
action: "pull_image"
|
||||
common_options: "{{ docker_common_options }}"
|
||||
image: "{{ telegraf_image_full }}"
|
||||
image: "{{ item.value.image }}"
|
||||
when:
|
||||
- inventory_hostname in groups[item.value.group]
|
||||
- item.value.enabled | bool
|
||||
with_dict: "{{ telegraf_services }}"
|
||||
|
@ -1,18 +0,0 @@
|
||||
---
|
||||
- name: Starting telegraf container
|
||||
kolla_docker:
|
||||
action: "start_container"
|
||||
common_options: "{{ docker_common_options }}"
|
||||
image: "{{ telegraf_image_full }}"
|
||||
name: "telegraf"
|
||||
environment:
|
||||
HOST_PROC: "/rootfs/proc"
|
||||
HOST_SYS: "/rootfs/sys"
|
||||
volumes:
|
||||
- "{{ node_config_directory }}/telegraf/:{{ container_config_directory }}/:ro"
|
||||
- "/etc/localtime:/etc/localtime:ro"
|
||||
- "kolla_logs:/var/log/kolla/"
|
||||
- "/sys:/rootfs/sys:ro"
|
||||
- "/proc:/rootfs/proc:ro"
|
||||
- "/var/run/docker.sock:/var/run/docker.sock:ro"
|
||||
pid_mode: "host"
|
@ -1,4 +1,5 @@
|
||||
---
|
||||
- include: config.yml
|
||||
|
||||
- include: start.yml
|
||||
- name: Flush handlers
|
||||
meta: flush_handlers
|
||||
|
Loading…
Reference in New Issue
Block a user