trying to create a state to configure filebeat for 20+ servers based on their minion id. for the sake of simplicity ive only included 3 of the types of server names. the following works, but its not ideal because it requires the exact minion id.
/etc/filebeat/filebeat.yml:
file.managed:
{% if grains[‘id]’ == “prod-varnish-01” %}
- source: salt://files/filebeat/varnish.yml
{% elif grains['id'] == “prod-nginx-01” %}
- source: salt://files/filebeat/nginx.yml
{% elif grains['id'] == “prod-api-01” %}
- source: salt://files/filebeat/api.yml
{% else %}
- source: salt://files/filebeat/default.yml
{% endif %}
- user: root
- group: root
- mode: '644'
- template: jinja
i’d like it to work in more of a regex kinda way such as:
/etc/filebeat/filebeat.yml:
file.managed:
{% if varnish in grains['id'] %}
- source: salt://files/filebeat/varnish.yml
{% elif nginx in grains['id'] %}
- source: salt://files/filebeat/nginx.yml
{% elif api in grains['id'] %}
- source: salt://files/filebeat/api.yml
{% else %}
- source: salt://files/filebeat/default.yml
{% endif %}
- user: root
- group: root
- mode: '644'
- template: jinja
with python string matching, but that doesn’t work and for the life of me i havent had any luck.
how would i achieve what i need?
{% if varnish in grains['id'] %}
- source: salt://files/filebeat/varnish.yml
{% elif nginx in grains['id'] %}
- source: salt://files/filebeat/nginx.yml