0
votes

I need create some configuration file in yml wtith ansible role. This example what i want:

filebeat.inputs:
- type: log
  paths:
    - /var/log/system.log
    - /var/log/wifi.log

In ansible dirctory structue in Templates dir i have file with such text:

filebeat.inputs:
- type: {{filebeat_input.type}}
  {{ filebeat_input.paths | to_yaml}}

In Directory defaults i have such main.yml: filebeat_create_config: true

filebeat_input:
    type: log
    paths:
     - "/var/log/*.log"
     - "/var/somelog/*.log"

When im run ansible-playbook with this role im got this:

filebeat.inputs:
  - type: log
  [/var/log/*.log, /var/sdfsadf]

Where i`m wrong ? what and where i need change to get exactly what i whant (see example above). Thanks for any help !

1

1 Answers

0
votes

filebeat_input.paths is a list, so when you pass it to to_yaml you get a list. You just need to structure your YAML template so that you're putting the list in the right place, e.g:

filebeat.inputs:
- type: {{filebeat_input.type}}
  paths: {{ filebeat_input.paths | to_yaml}}

Note that:

paths: [/var/log/*.log, /var/sdfsadf]

Is exactly equivalent to:

paths:
  - /var/log/*.log
  - /var/sdfsadf