add telegraf.d support
This commit is contained in:
		@@ -25,6 +25,18 @@
 | 
			
		||||
    mode: 0644
 | 
			
		||||
  notify: reload telegraf
 | 
			
		||||
 | 
			
		||||
- name: configure telegraf.d files
 | 
			
		||||
  template:
 | 
			
		||||
    src: telegraf_d.conf.j2
 | 
			
		||||
    dest: "/etc/telegraf/telegraf.d/{{ '%02d' | format(idx) }}-{{ item.name }}.conf"
 | 
			
		||||
    owner: root
 | 
			
		||||
    group: root
 | 
			
		||||
    mode: 0644
 | 
			
		||||
  notify: reload telegraf
 | 
			
		||||
  loop: "{{ telegraf_config_d | default([]) }}"
 | 
			
		||||
  loop_control:
 | 
			
		||||
    index_var: idx
 | 
			
		||||
 | 
			
		||||
- name: create systemd override directory
 | 
			
		||||
  file:
 | 
			
		||||
    path: /etc/systemd/system/telegraf.service.d
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										40
									
								
								roles/telegraf/templates/telegraf_d.conf.j2
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								roles/telegraf/templates/telegraf_d.conf.j2
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
			
		||||
# {{ ansible_managed }}
 | 
			
		||||
 | 
			
		||||
{% macro toml_scalar(v, seq=False) %}
 | 
			
		||||
{% if v is string %}
 | 
			
		||||
  "{{ v | quote }}"{% if seq %},{% endif %}
 | 
			
		||||
{% elif v is sameas True or v is sameas False %}
 | 
			
		||||
  {{ v | bool | lower }}{% if seq %},{% endif %}
 | 
			
		||||
{% elif v is sameas None %}
 | 
			
		||||
  ""{% if seq %},{% endif %}
 | 
			
		||||
{% elif v is number %}
 | 
			
		||||
  {{ v }}{% if seq %},{% endif %}
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% endmacro %}
 | 
			
		||||
 | 
			
		||||
{% if item.config %}
 | 
			
		||||
{% for name, config in item.config.items() | default({}) %}
 | 
			
		||||
{% for c in config %}
 | 
			
		||||
[[{{ name }}]]
 | 
			
		||||
{% for k, v in c.items() | default({}) %}
 | 
			
		||||
{% if v is string %}
 | 
			
		||||
  {{ k }} = "{{ v | quote }}"
 | 
			
		||||
{% elif v is sameas True or v is sameas False %}
 | 
			
		||||
  {{ k }} = {{ v | bool | lower }}
 | 
			
		||||
{% elif v is sameas None %}
 | 
			
		||||
  {{ k }} = ""
 | 
			
		||||
{% elif v is number %}
 | 
			
		||||
  {{ k }} = {{ v }}
 | 
			
		||||
{% elif v is sequence %}
 | 
			
		||||
  {{ k }} = [
 | 
			
		||||
{% for i in v | default([]) %}
 | 
			
		||||
    {{ toml_scalar(i, seq=True) }}
 | 
			
		||||
{% endfor %}
 | 
			
		||||
  ]
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% endfor %}
 | 
			
		||||
{% else %}
 | 
			
		||||
[[{{ name }}]]
 | 
			
		||||
{% endfor %}
 | 
			
		||||
{% endfor %}
 | 
			
		||||
{% endif %}
 | 
			
		||||
		Reference in New Issue
	
	Block a user