All technological notes.
templating
Ansible uses the Jinja2 templating engine (same as in Flask/Django) to achieve this.
.j2Example
nginx.conf.j2
server {
listen 80;
server_name ;
location / {
proxy_pass http://:;
}
}
- hosts: webservers
vars:
server_name: mysite.com
backend_host: 127.0.0.1
backend_port: 5000
tasks:
- name: Deploy nginx configuration
template:
src: templates/nginx.conf.j2
dest: /etc/nginx/nginx.conf
notify: Restart nginx
# Variable substitution
Hello
# Default values:
# Conditionals:
DEBUG = True
# Loops:
# Filters
hello # Output: HELLO
# Join list into a string
/etc/hosts # hosts
c:\windows\hosts # hosts, in windows
c:\windows\hosts # ["c:","\windows\hosts"]
# "c:"