Merge "Optimize reconfigure action for telegraf"

This commit is contained in:
Jenkins 2017-01-27 15:30:20 +00:00 committed by Gerrit Code Review
commit 700089f5b3
7 changed files with 96 additions and 25 deletions

View File

@ -1,6 +1,22 @@
--- ---
project_name: "telegraf" 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 # Docker
#################### ####################

View 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

View File

@ -1,26 +1,68 @@
--- ---
- name: Ensuring config directories exist - name: Ensuring config directories exist
file: file:
path: "{{ node_config_directory }}/{{ item }}" path: "{{ node_config_directory }}/{{ item.key }}/config"
state: "directory" state: "directory"
recurse: yes recurse: yes
with_items: when:
- "telegraf" - inventory_hostname in groups[item.value.group]
- "telegraf/config" - item.value.enabled | bool
with_dict: "{{ telegraf_services }}"
- name: Copying over default config.json files - name: Copying over default config.json files
vars:
service: "{{ telegraf_services['telegraf_services'] }}"
template: template:
src: "telegraf.json.j2" src: "telegraf.json.j2"
dest: "{{ node_config_directory }}/telegraf/config.json" 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 - name: Copying over telegraf config file
vars:
service: "{{ telegraf_services['telegraf'] }}"
template: template:
src: "telegraf.conf.j2" src: "telegraf.conf.j2"
dest: "{{ node_config_directory }}/telegraf/telegraf.conf" 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 - name: Copying over telegraf plugin files
vars:
service: "{{ telegraf_services['telegraf'] }}"
copy: copy:
src: "{{ item }}" src: "{{ item }}"
dest: "{{ node_config_directory }}/telegraf/config" dest: "{{ node_config_directory }}/telegraf/config"
register: telegraf_plugin
when:
- inventory_hostname in groups[service.group]
- item.value.enabled | bool
with_fileglob: with_fileglob:
- "{{ role_path }}/templates/config/*.conf" - "{{ 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

View File

@ -1,4 +1,5 @@
--- ---
- include: config.yml - include: config.yml
- include: start.yml - name: Flush handlers
meta: flush_handlers

View File

@ -3,4 +3,8 @@
kolla_docker: kolla_docker:
action: "pull_image" action: "pull_image"
common_options: "{{ docker_common_options }}" 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 }}"

View File

@ -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"

View File

@ -1,4 +1,5 @@
--- ---
- include: config.yml - include: config.yml
- include: start.yml - name: Flush handlers
meta: flush_handlers