ansible Templates:模版

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值