微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

 

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐