用的不是yaml語言而是jinja2
templates目錄與playbook檔案所在平級
模闆樣例,字尾為.j2
/etc/nginx.conf.j2
==========================
- hosts: a
remote_user: root
tasks:
- name: install package
yum: name = nginx
- name: copy template
template: src = nginx.conf.j2 dest=/etc/nginx/nginx.conf
- name: start service
service: name = nginx state = started enabled = yes
when
---
- hosts: a
remote_user: root
tasks:
- name: install on centos6
template: src=f1.j2 dest=/tmp/f.conf
when: ansible_distribution_major_version == "6"
- name: install on centos7
template: src=f2.j2 dest=/tmp/f.conf
when: ansible_distribution_major_version == "7"