Junior — Middle
Have you used Jinja2 templates within Ansible for configuration automation?
sobes.tech AI
Answer from AI
Yes, Jinja2 templates are frequently used in Ansible for dynamic generation of configuration files. This allows variables to be substituted, and conditions and loops to be used directly within templates, greatly simplifying automation.
Example of using a Jinja2 template in Ansible:
- name: Create a configuration file from a template
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
In the nginx.conf.j2 file, variables can be used, for example:
server {
listen {{ nginx_port }};
server_name {{ server_name }};
}
This makes it easy to change configuration parameters without editing the file itself, by only managing variables in Ansible.