---恢复内容开始---
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><!--Tags用于选择运行或路过playbook中的部分代码,ansible具有幂等性,因此会自动跳过没有变化的部分,即便如此,有些代码为测试其确实没有发生变化的时间依然会非常长,此时,如果确信其没有变化,就可以通过tags跳过此些代码片段--></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-playbook nginx_temp.yml --tags="conf" 指定tags运行
# 特殊tags: always 无论如何都会运行
---恢复内容结束---
原文地址:https://www.cnblogs.com/c040/p/10358096.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。