playbook变量(七)template 基本使用 when

1、模拟6和7系统(6对应11、7对应12)

[root@linux-node1 ansible]# cat test_template2.yaml 
---
- hosts: date
  remote_user: root
  vars:
    - http_port: 99

  tasks:
    - name: install package
      yum: name=nginx
    - name: copy 7 template
      template: src=nginx.conf11.j2 dest=/etc/nginx/nginx.conf
      when: ansible_distribution_major_version == "7"
      notify: restart service
    - name: copy 6 template
      template: src=nginx.conf12.j2 dest=/etc/nginx/nginx.conf
      when: ansible_distribution_major_version == "6"
      notify: restart service
    - name: start service
      service: name=nginx state=started enabled=yes

  handlers:
    - name: restart service
      service: name=nginx state=restarted 

 

 

 

 

posted @ 2020-01-02 11:43  随心朝阳  阅读(369)  评论(0编辑  收藏  举报