---恢复内容开始---
Templates:模版
cat /etc/ansible/hosts
![技术分享图片]()

cat templates/nginx.conf.j2

![技术分享图片]()
- hosts: test
remote_user: root
vars:
- package: httpd
- service: httpd
tasks:
- name: install nginx package
yum: name={{ package }} state=latest
- name: install configuration file for httpd
template: src=/root/templates/httpd.conf.j2 dest=/etc/httpd/conf/httpd.conf
notify:
- restart httpd
- name: start httpd service
service: enabled=true name={{ service }} state=started
handlers:
- name: restart httpd
service: name={{ package }} state=restarted
tags 标签
<u></u>
- hosts: test
remote_user: root
vars:
- package: nginx
- service: nginx
tasks:
- name: install nginx package
yum: name={{ package }} state=latest
tags:
- install
- name: configuration file for httpd
tags:
- conf
template: src=/root/templates/nginx.conf.j2 dest=/etc/nginx/nginx.conf
notify:
- restart nginx
- name: start nginx service
shell: nginx
tags:
- start_nginx
handlers:
- name: restart nginx
shell: nginx -s reload
---恢复内容结束---
ansible Templates:模版
原文:https://www.cnblogs.com/c040/p/10358096.html