我正在使用Ansible为我的Ruby on Rails应用程序提供环境。
我想知道是否可以在ansible复制之前对我的ERB模板进行预处理?解决此问题的最佳方法是什么?
最终目标是拥有类似这样的模板:
my_template.conf.erb
timeout: 2000
secret_key: <%= ENV['THE_SECRET_KEY'] %>
任何技巧都将不胜感激。
是
您必须使用与erb模板非常相似的jinja2模板。
my_template.conf.j2
timeout: 2000
secret_key: {{ secret_key }}
在您的剧本中,类似:
- name: Template config
hosts: all
user: myuser
sudo: True
tags: mytag
vars:
- secret_key: "{{ lookup('env','THE_SECRET_KEY') }}"
tasks:
- name: Do template substitution
template: src=templates/my_template.conf.j2 dest=/etc/myapp/myconf.conf owner=root group=root mode=0644