Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkhaja/f58ade17d54d7cec5276 to your computer and use it in GitHub Desktop.
Save rkhaja/f58ade17d54d7cec5276 to your computer and use it in GitHub Desktop.
Example of converting logback.xml from Cassandra configuration into a jinja template using Ansible
---
- name: Copy logback.xml file to templates directory to make Jinja2 template
copy:
src: "{{ cassandra_role_dir }}/files/apache-cassandra-{{ cassandra_version }}/conf/logback.xml"
dest: "{{ cassandra_role_dir }}/templates/apache-cassandra-{{ cassandra_version }}/conf/logback.xml.j2"
- name: Make Jinga2 template for logback.xml
lineinfile:
dest: "{{ cassandra_role_dir }}/templates/apache-cassandra-{{ cassandra_version }}/conf/logback.xml.j2"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- [ { regexp: '<file>\${cassandra.logdir}/system.log</file>',
line: ' <file>__OPEN_BRACES__ path_to_cassandra_system_log __CLOSE_BRACES__</file>' },
{ regexp: '<fileNamePattern>\${cassandra.logdir}/system.log.%i.zip</fileNamePattern>',
line: ' <fileNamePattern>__OPEN_BRACES__ path_to_cassandra_system_log __CLOSE_BRACES__.%i.zip</fileNamePattern>' },
{ regexp: "<maxIndex>20</maxIndex>",
line: ' <maxIndex>__OPEN_BRACES__ max_index __CLOSE_BRACES__</maxIndex>' },
]
- include: fix_braces_in_template_file.yml template_file="{{ cassandra_role_dir }}/templates/apache-cassandra-{{ cassandra_version }}/conf/logback.xml.j2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment