salt-formulas / salt-formula-telegraf

Other
3 stars 11 forks source link

Rendering SLS 'base:telegraf.agent' failed: Jinja variable 'str object' has no attribute 'get' #2

Open brenwhyte opened 6 years ago

brenwhyte commented 6 years ago

Getting the below render error from Salt.

    Data failed to compile:
----------
    Rendering SLS 'base:telegraf.agent' failed: Jinja variable 'str object' has no attribute 'get'
/var/cache/salt/minion/files/base/telegraf/map.jinja(23):
---
[...]
}, merge=salt['pillar.get']('telegraf:remote_agent')) %}

{# Collect configuration from */meta/telegraf.yml #}
{%- set telegraf_grains = {'telegraf': {'agent': {'input': {}}, 'remote_agent': {'input':{}, 'output':{}}}} %}
{%- for service_name, service in pillar.items() %}
  {%- if service.get('_support', {}).get('telegraf', {}).get('enabled', False) %}    <======================
    {%- set grains_fragment_file = service_name+'/meta/telegraf.yml' %}
    {%- macro load_grains_file() %}{% include grains_fragment_file ignore missing %}{% endmacro %}
    {%- set grains_yaml = load_grains_file()|load_yaml %}
    {%- if grains_yaml is mapping %}
      {%- set telegraf_grains = salt['grains.filter_by']({'default': telegraf_grains}, merge={'telegraf': grains_yaml}) %}
[...]
---

Basic pillar file:

telegraf:
  agent:
    enabled: true
    output:
      influxdb:
        urls:
          - http://127.0.0.1:9096
        database: telegraf
    input:
      cpu:
        totalcpu: totalcpu_value

Any thoughts?

gcotone commented 5 years ago

@brenwhyte same here, did you find a workaround?

krombel commented 5 years ago

I had the same issue. The reason for this was my pillar setup: I had to make sure, that all pillar entries are dictionaries.

To debug this I pushed this template file via file.managed to /tmp/test

{%- for service_name, service in pillar.items() %}
{{ service_name }} - {{ service }}
{%- endfor %}

You need to make sure that there a no entries like: name - ["asdf"] or name - asdf. This formular only supports name - {"asdf":42}

The reason for this is service.get(...) where service is a string or an array or anything not a dictionary.

Applying #4 should fix the issue