Rendering the variables

I have defined the variable like below:-

input_host_ports:

  • 4000:fluent:syslog

  • 4500:json:log

  • 4800:plain:debuglog

I want to get the render the variables in the jinja2 for loop like below:

tcp {
port => 4000
codec => fluent

type => syslog
}
tcp {
port => 4500
codec => json {
charset => “ISO-8859-1”
}

type => debuglog
}

tcp {
port => 4800
codec => plain

type => debuglog
}

Only for the port 4500 - I want the charset and also the output should be exactly in this format and in future I may add new ports if required.

Start by defining your variable as a list of dicts, so you can easily
iterate over them:

input_host_ports:
  - port: 4000
    codec: fluent
    type: syslog
  - port: 5500
    codec: json
    type: debuglog
    charset: ISO-8859-1
  - port: 4800
    codec: plain
    type: debuglog

Dick

Thanks Dick, it worked.