首页 > 其他 > 详细

ansible Templates:模版

时间:2019-02-09 21:53:15      阅读:180      评论:0      收藏:0      [点我收藏+]

---恢复内容开始---

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 无论如何都会运行

 

---恢复内容结束---

ansible Templates:模版

原文:https://www.cnblogs.com/c040/p/10358096.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!