I have a cloud-init script, that is using jinja templating. It looks like this:
## template: jinja
#cloud-config
merge_how:
- name: list
settings: [append]
- name: dict
settings: [no_replace, recurse_list]
runcmd:
- mkdir -p /opt/collectd
write_files:
- path: /opt/collectd/collectd.conf
content: |
Hostname "connect-${connect_group_id}"
FQDNLookup false
Interval 60
<LoadPlugin write_graphite>
Globals false
</LoadPlugin>
LoadPlugin cpu
LoadPlugin disk
LoadPlugin df
LoadPlugin memory
LoadPlugin swap
LoadPlugin interface
LoadPlugin tcpconns
<Plugin df>
MountPoint "/hostfs"
MountPoint "/hostfs/var/lib"
MountPoint "/hostfs/var/log"
IgnoreSelected false
ReportInodes false
</Plugin>
<Plugin interface>
Interface "eth0"
IgnoreSelected false
</Plugin>
<Plugin swap>
ReportByDevice false
ReportBytes true
</Plugin>
<Plugin tcpconns>
ListeningPorts false
LocalPort "${jmx_port}"
RemotePort "${jmx_port}"
</Plugin>
LoadPlugin processes
<Plugin processes>
CollectFileDescriptor true
CollectContextSwitch false
CollectMemoryMaps false
ProcessMatch "zookeeper" ".*QuorumPeerMain.*"
ProcessMatch "kafka" ".*SupportedKafka.*"
</Plugin>
# JMX Plugin Config
LoadPlugin java
{% macro mbean(objectName, name, type, instancePrefix, table, attribute) -%}
<MBean "{{ name }}">
ObjectName "{{ objectName }}"
<Value>
Type "{{ type }}"
InstancePrefix "{{ instancePrefix }}"
Table {{ table }}
Attribute "{{ attribute }}"
</Value>
</MBean>
{% endmacro %}
<Plugin java>
JVMARG "-Djava.class.path=/usr/share/collectd/java/collectd-api.jar:/usr/share/collectd/java/generic-jmx.jar"
LoadPlugin "org.collectd.java.GenericJMX"
<Plugin "GenericJMX">
{% set metrics=[
"connector-count",
"connector-startup-attempts-total",
"connector-startup-failure-total",
"connector-startup-failure-percentage",
"connector-startup-success-total",
"connector-startup-success-percentage",
"task-count",
"task-startup-attempts-total",
"task-startup-failure-total",
"task-startup-failure-percentage",
"task-startup-success-total",
"task-startup-success-percentage",
] -%}
{% for name in metrics -%}
{{ mbean(
"kafka.connect:type=connect-worker-metrics",
name,
"counter",
name,
"false",
"Value")
}}
{%- endfor %}
When this script gets specialized and written to the machine, the Jinja markup doesnt get processed.
I took the collectd.conf file and ran it through jinja myself, and it was generated output correctly. So there is no problem with the jinja template itself.
I also looked at the output of /var/log/cloud-init.log and /var/log/cloud-init-output.log and didnt see any errors.
any help appreciated.