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

 

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

猜你喜欢

转载自www.cnblogs.com/c040/p/10358096.html